Search is not available for this dataset
repo_name string | path string | license string | full_code string | full_size int64 | uncommented_code string | uncommented_size int64 | function_only_code string | function_only_size int64 | is_commented bool | is_signatured bool | n_ast_errors int64 | ast_max_depth int64 | n_whitespaces int64 | n_ast_nodes int64 | n_ast_terminals int64 | n_ast_nonterminals int64 | loc int64 | cycloplexity int64 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
limansky/Hascal | src/Hascal.hs | bsd-3-clause | importICS fn = do
putStrLn $ "Importing file:" ++ fn
h <- openFile fn ReadMode
cont <- hGetContents h
case icalToEvents cont of
Nothing -> putStrLn "Failed to parse ICS file"
(Just es) -> mapM (putStrLn . show) es >> return ()
hClose h | 272 | importICS fn = do
putStrLn $ "Importing file:" ++ fn
h <- openFile fn ReadMode
cont <- hGetContents h
case icalToEvents cont of
Nothing -> putStrLn "Failed to parse ICS file"
(Just es) -> mapM (putStrLn . show) es >> return ()
hClose h | 272 | importICS fn = do
putStrLn $ "Importing file:" ++ fn
h <- openFile fn ReadMode
cont <- hGetContents h
case icalToEvents cont of
Nothing -> putStrLn "Failed to parse ICS file"
(Just es) -> mapM (putStrLn . show) es >> return ()
hClose h | 272 | false | false | 0 | 13 | 80 | 100 | 44 | 56 | null | null |
ComputationWithBoundedResources/ara-inference | doc/tpdb_trs/Haskell/basic_haskell/enumFromThenTo_6.hs | mit | takeWhile0 p x xs MyTrue = Nil | 30 | takeWhile0 p x xs MyTrue = Nil | 30 | takeWhile0 p x xs MyTrue = Nil | 30 | false | false | 0 | 5 | 6 | 15 | 7 | 8 | null | null |
koterpillar/tianbar | src/System/Tianbar/Callbacks.hs | mit | newCallbackT :: (MonadState Callbacks m, ToJSON r) => m (Callback r, CallbackIndex)
newCallbackT = do
host <- use cbHost
newIndex <- use cbNextIndex
cbNextIndex += 1
return (host newIndex . toJSON, CallbackIndex newIndex) | 237 | newCallbackT :: (MonadState Callbacks m, ToJSON r) => m (Callback r, CallbackIndex)
newCallbackT = do
host <- use cbHost
newIndex <- use cbNextIndex
cbNextIndex += 1
return (host newIndex . toJSON, CallbackIndex newIndex) | 237 | newCallbackT = do
host <- use cbHost
newIndex <- use cbNextIndex
cbNextIndex += 1
return (host newIndex . toJSON, CallbackIndex newIndex) | 153 | false | true | 0 | 10 | 48 | 89 | 42 | 47 | null | null |
mathhun/stack | src/Path/IO.hs | bsd-3-clause | -- | Make a directory tree, creating parents if needed.
createTree :: MonadIO m => Path b Dir -> m ()
createTree = liftIO . D.createDirectoryIfMissing True . toFilePath | 168 | createTree :: MonadIO m => Path b Dir -> m ()
createTree = liftIO . D.createDirectoryIfMissing True . toFilePath | 112 | createTree = liftIO . D.createDirectoryIfMissing True . toFilePath | 66 | true | true | 0 | 8 | 28 | 46 | 22 | 24 | null | null |
haskell/haddock | haddock-api/src/Haddock/Backends/Xhtml/Decl.hs | bsd-2-clause | ppPatSigType :: Unicode -> Qualification -> LHsSigType DocNameI -> Html
ppPatSigType unicode qual typ =
let emptyCtxts = patSigContext typ in ppLSigType unicode qual emptyCtxts typ | 182 | ppPatSigType :: Unicode -> Qualification -> LHsSigType DocNameI -> Html
ppPatSigType unicode qual typ =
let emptyCtxts = patSigContext typ in ppLSigType unicode qual emptyCtxts typ | 182 | ppPatSigType unicode qual typ =
let emptyCtxts = patSigContext typ in ppLSigType unicode qual emptyCtxts typ | 110 | false | true | 0 | 9 | 27 | 61 | 27 | 34 | null | null |
nevrenato/Hets_Fork | OWL2/ProfilesAndSublogics.hs | gpl-2.0 | sMorph :: OWLMorphism -> ProfSub
sMorph m = bottomS {sublogic = slMor m} | 72 | sMorph :: OWLMorphism -> ProfSub
sMorph m = bottomS {sublogic = slMor m} | 72 | sMorph m = bottomS {sublogic = slMor m} | 39 | false | true | 0 | 8 | 12 | 38 | 17 | 21 | null | null |
keera-studios/hsQt | Qtc/Enums/Core/QDir.hs | bsd-2-clause | eAllDirs :: Filter
eAllDirs
= ieFilter $ 1024 | 47 | eAllDirs :: Filter
eAllDirs
= ieFilter $ 1024 | 47 | eAllDirs
= ieFilter $ 1024 | 28 | false | true | 0 | 6 | 9 | 18 | 8 | 10 | null | null |
kawamuray/ganeti | src/Ganeti/HTools/Program/Hbal.hs | gpl-2.0 | execCancelWrapper anno master nl il cref alljss = do
cancel <- readIORef cref
if cancel > 0
then do
putStrLn $ "Exiting early due to user request, " ++
show (length alljss) ++ " jobset(s) remaining."
return $ Ok ()
else execJobSet anno master nl il cref alljss
-- | Execute an entire jobset. | 331 | execCancelWrapper anno master nl il cref alljss = do
cancel <- readIORef cref
if cancel > 0
then do
putStrLn $ "Exiting early due to user request, " ++
show (length alljss) ++ " jobset(s) remaining."
return $ Ok ()
else execJobSet anno master nl il cref alljss
-- | Execute an entire jobset. | 331 | execCancelWrapper anno master nl il cref alljss = do
cancel <- readIORef cref
if cancel > 0
then do
putStrLn $ "Exiting early due to user request, " ++
show (length alljss) ++ " jobset(s) remaining."
return $ Ok ()
else execJobSet anno master nl il cref alljss
-- | Execute an entire jobset. | 331 | false | false | 0 | 14 | 93 | 94 | 44 | 50 | null | null |
mpickering/HaRe | test/UtilsSpec.hs | bsd-3-clause | spec :: Spec
spec = do
describe "locToExp on ParsedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,43) parsed :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
it "finds the largest leftmost expression contained in a given region #2" $ do
-- ((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,41) modu :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
it "finds the largest leftmost expression in RenamedSource" $ do
-- ((_, renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,41) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
describe "locToExp on RenamedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
-- ((_, Just renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,43) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
-- -------------------------------------------------------------------
describe "loading a file" $ do
it "loads a file having the LANGUAGE CPP pragma" $ do
(_t, toks,_) <- ct $ parsedFileGhc "./BCpp.hs"
-- let renamed = fromJust $ GHC.tm_renamed_source t
-- let (Just expr) = locToExp (6,1) (12,1) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
origStr <- readFile "./test/testdata/BCpp.hs"
let toksStr = (GHC.showRichTokenStream toks)
-- (show (filter (\(c,_) -> c /= B) $ getGroupedDiff (lines toksStr) (lines origStr))) `shouldBe` "[]"
(show $ compareStrings toksStr origStr) `shouldBe` "[]"
-- -----------------------------------
it "loads a series of files based on cabal1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal1"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
let settings = defaultSettings { rsetEnabledTargets = (True,True,False,False)
-- , rsetVerboseLevel = Debug
}
r <- rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)
-- r <- rename logTestSettings cradle "./src/Foo/Bar.hs" "baz1" (3, 1)
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","
++"\"test/testdata/cabal/cabal1/src/main.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal2, which has 2 exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","++
"\"test/testdata/cabal/cabal2/src/main1.hs\","++
"\"test/testdata/cabal/cabal2/src/main2.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal3, which has a lib and an exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal3"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/main1.hs" "baz1" (7, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/main1.hs\"]"
-- -----------------------------------
{- TODO: this test fails on travis, due to missing hspec-discover
it "renames in HaRe Utils 1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./src/Language/Haskell/Refact/Utils.hs" "clientModsAndFiles1" (473, 6)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
it "renames in HaRe Utils 2" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
, rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 10)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
-- This test does not work properly on Travis, missing hspec-discover
it "renames in HaRe Utils 3" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 11)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"test/UtilsSpec.hs\"]"
-}
-- -------------------------------------------------------------------
describe "sameOccurrence" $ do
it "checks that a given syntax element is the same occurrence as another" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "isVarId" $ do
it "returns True if a string is a lexically valid variable name" $ do
isVarId "foo" `shouldBe` True
it "returns False if a string is not lexically valid variable name" $ do
isVarId "Foo" `shouldBe` False
-- -------------------------------------------------------------------
describe "getModuleName" $ do
it "returns a string for the module name if there is one" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just (_modname,modNameStr)) = getModuleName modu
-- let modNameStr = "foo"
modNameStr `shouldBe` "TypeUtils.B"
it "returns Nothing for the module name otherwise" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileNoMod
(t, _toks,_) <- parsedFileNoMod
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
getModuleName modu `shouldBe` Nothing
-- -------------------------------------------------------------------
describe "modIsExported" $ do
it "needs a test or two" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "clientModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
------------------------------------
it "gets modules which directly or indirectly import a module #1" $ do
-- TODO: harvest this commonality
-- (t, toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./M3.hs"
getModuleGhc "./S1.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialLogOnState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
------------------------------------
it "gets modules which directly or indirectly import a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
getModuleGhc "./M3.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "M3"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main]"
------------------------------------
it "gets modules which import a module in different cabal targets" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
let
comp = do
initGhcSession [Left "./src/main1.hs"]
getModuleGhc "./src/Foo/Bar.hs" -- Load the file first
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "Foo.Bar"
g <- clientModsAndFiles tm
return g
-- (mg,_s) <- runRefactGhcState comp
-- (mg,_s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(mg,_s) <- runRefactGhc comp [Left "./src/main1.hs"] (initialState { rsModule = Nothing }) testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, Main]"
setCurrentDirectory currentDir
-- -------------------------------------------------------------------
describe "serverModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
it "gets modules which are directly or indirectly imported by a module #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "S1"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp tgt (initialLogOnState { rsModule = initRefactModule t }) testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[]"
it "gets modules which are directly or indirectly imported by a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M3.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "M3"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M3.hs"] initialState testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[M2, S1]"
-- -------------------------------------------------------------------
{-
describe "getCurrentModuleGraph" $ do
it "gets the module graph for the currently loaded modules" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- getCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
map (\m -> GHC.moduleNameString $ GHC.ms_mod_name m) mg `shouldBe` (["TypeUtils.B","TypeUtils.C"])
map (\m -> show $ GHC.ml_hs_file $ GHC.ms_location m) mg `shouldBe` (["Just \"./test/testdata/TypeUtils/B.hs\""
,"Just \"./test/testdata/TypeUtils/C.hs\""])
it "gets the updated graph, after a refactor" $ do
pending -- "write this test"
-}
-- -------------------------------------------------------------------
{-
describe "sortCurrentModuleGraph" $ do
it "needs a test or two" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- sortCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
(showGhc $ map (\m -> GHC.ms_mod m) (GHC.flattenSCCs mg)) `shouldBe` "[main:TypeUtils.C, main:TypeUtils.B]"
-}
-- -------------------------------------------------------------------
describe "getModuleGhc" $ do
it "retrieves a module from an existing module graph #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./test/testdata/S1.hs"
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
( (t, mg), _s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "loads the module and dependents if no existing module graph" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./S1.hs"
let
comp = do
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg ), _s) <- ct $ runRefactGhc comp [Left "./S1.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "retrieves a module from an existing module graph #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/DupDef/Dd2.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./DupDef/Dd2.hs"]
getModuleGhc "./DupDef/Dd1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "DupDef.Dd1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg), _s) <- ct $ runRefactGhc comp [Left "DupDef/Dd2.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"DupDef.Dd1\",\"DupDef.Dd1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[DupDef.Dd2, DupDef.Dd3]"
-- -------------------------------------------------------------------
describe "runRefactGhc" $ do
it "contains a State monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (_,s) <- runRefactGhcState comp
(_,s) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
(rsUniqState s) `shouldBe` 100
it "contains the GhcT monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (r,_) <- runRefactGhcState comp
(r,_) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
r `shouldBe` ("[\"TypeUtils.B ( TypeUtils/B.hs, nothing )\","
++"\"TypeUtils.C ( TypeUtils/C.hs, nothing )\"]")
-- -------------------------------------------------------------------
describe "RefactFlags" $ do
it "puts the RefactDone flag through its paces" $ do
(t,_toks,tgt) <- ct $ parsedFileGhc "./FreeAndDeclared/DeclareTypes.hs"
let
comp = do
v1 <- getRefactDone
clearRefactDone
v2 <- getRefactDone
setRefactDone
v3 <- getRefactDone
return (v1,v2,v3)
-- ((v1',v2',v3'), _s) <- runRefactGhcState comp
((v1',v2',v3'), _s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(show (v1',v2',v3')) `shouldBe` "(False,False,True)"
-- ---------------------------------------------------------------------
-- Helper functions
-- bFileName :: GHC.FastString
-- bFileName = GHC.mkFastString "./test/testdata/TypeUtils/B.hs"
-- parsedFileBGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileBGhc = ct $ parsedFileGhc "./TypeUtils/B.hs"
-- parsedFileMGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileMGhc = parsedFileGhc "./test/testdata/M.hs"
-- parseFileBGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileBGhc = parseSourceFileTest fileName
-- where
-- fileName = "./test/testdata/TypeUtils/B.hs"
-- parseFileMGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileMGhc = parseSourceFileTest fileName
-- where
-- fileName = "./M.hs" | 22,815 | spec :: Spec
spec = do
describe "locToExp on ParsedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,43) parsed :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
it "finds the largest leftmost expression contained in a given region #2" $ do
-- ((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,41) modu :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
it "finds the largest leftmost expression in RenamedSource" $ do
-- ((_, renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,41) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
describe "locToExp on RenamedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
-- ((_, Just renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,43) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
-- -------------------------------------------------------------------
describe "loading a file" $ do
it "loads a file having the LANGUAGE CPP pragma" $ do
(_t, toks,_) <- ct $ parsedFileGhc "./BCpp.hs"
-- let renamed = fromJust $ GHC.tm_renamed_source t
-- let (Just expr) = locToExp (6,1) (12,1) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
origStr <- readFile "./test/testdata/BCpp.hs"
let toksStr = (GHC.showRichTokenStream toks)
-- (show (filter (\(c,_) -> c /= B) $ getGroupedDiff (lines toksStr) (lines origStr))) `shouldBe` "[]"
(show $ compareStrings toksStr origStr) `shouldBe` "[]"
-- -----------------------------------
it "loads a series of files based on cabal1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal1"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
let settings = defaultSettings { rsetEnabledTargets = (True,True,False,False)
-- , rsetVerboseLevel = Debug
}
r <- rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)
-- r <- rename logTestSettings cradle "./src/Foo/Bar.hs" "baz1" (3, 1)
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","
++"\"test/testdata/cabal/cabal1/src/main.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal2, which has 2 exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","++
"\"test/testdata/cabal/cabal2/src/main1.hs\","++
"\"test/testdata/cabal/cabal2/src/main2.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal3, which has a lib and an exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal3"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/main1.hs" "baz1" (7, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/main1.hs\"]"
-- -----------------------------------
{- TODO: this test fails on travis, due to missing hspec-discover
it "renames in HaRe Utils 1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./src/Language/Haskell/Refact/Utils.hs" "clientModsAndFiles1" (473, 6)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
it "renames in HaRe Utils 2" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
, rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 10)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
-- This test does not work properly on Travis, missing hspec-discover
it "renames in HaRe Utils 3" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 11)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"test/UtilsSpec.hs\"]"
-}
-- -------------------------------------------------------------------
describe "sameOccurrence" $ do
it "checks that a given syntax element is the same occurrence as another" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "isVarId" $ do
it "returns True if a string is a lexically valid variable name" $ do
isVarId "foo" `shouldBe` True
it "returns False if a string is not lexically valid variable name" $ do
isVarId "Foo" `shouldBe` False
-- -------------------------------------------------------------------
describe "getModuleName" $ do
it "returns a string for the module name if there is one" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just (_modname,modNameStr)) = getModuleName modu
-- let modNameStr = "foo"
modNameStr `shouldBe` "TypeUtils.B"
it "returns Nothing for the module name otherwise" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileNoMod
(t, _toks,_) <- parsedFileNoMod
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
getModuleName modu `shouldBe` Nothing
-- -------------------------------------------------------------------
describe "modIsExported" $ do
it "needs a test or two" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "clientModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
------------------------------------
it "gets modules which directly or indirectly import a module #1" $ do
-- TODO: harvest this commonality
-- (t, toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./M3.hs"
getModuleGhc "./S1.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialLogOnState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
------------------------------------
it "gets modules which directly or indirectly import a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
getModuleGhc "./M3.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "M3"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main]"
------------------------------------
it "gets modules which import a module in different cabal targets" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
let
comp = do
initGhcSession [Left "./src/main1.hs"]
getModuleGhc "./src/Foo/Bar.hs" -- Load the file first
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "Foo.Bar"
g <- clientModsAndFiles tm
return g
-- (mg,_s) <- runRefactGhcState comp
-- (mg,_s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(mg,_s) <- runRefactGhc comp [Left "./src/main1.hs"] (initialState { rsModule = Nothing }) testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, Main]"
setCurrentDirectory currentDir
-- -------------------------------------------------------------------
describe "serverModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
it "gets modules which are directly or indirectly imported by a module #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "S1"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp tgt (initialLogOnState { rsModule = initRefactModule t }) testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[]"
it "gets modules which are directly or indirectly imported by a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M3.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "M3"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M3.hs"] initialState testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[M2, S1]"
-- -------------------------------------------------------------------
{-
describe "getCurrentModuleGraph" $ do
it "gets the module graph for the currently loaded modules" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- getCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
map (\m -> GHC.moduleNameString $ GHC.ms_mod_name m) mg `shouldBe` (["TypeUtils.B","TypeUtils.C"])
map (\m -> show $ GHC.ml_hs_file $ GHC.ms_location m) mg `shouldBe` (["Just \"./test/testdata/TypeUtils/B.hs\""
,"Just \"./test/testdata/TypeUtils/C.hs\""])
it "gets the updated graph, after a refactor" $ do
pending -- "write this test"
-}
-- -------------------------------------------------------------------
{-
describe "sortCurrentModuleGraph" $ do
it "needs a test or two" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- sortCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
(showGhc $ map (\m -> GHC.ms_mod m) (GHC.flattenSCCs mg)) `shouldBe` "[main:TypeUtils.C, main:TypeUtils.B]"
-}
-- -------------------------------------------------------------------
describe "getModuleGhc" $ do
it "retrieves a module from an existing module graph #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./test/testdata/S1.hs"
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
( (t, mg), _s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "loads the module and dependents if no existing module graph" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./S1.hs"
let
comp = do
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg ), _s) <- ct $ runRefactGhc comp [Left "./S1.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "retrieves a module from an existing module graph #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/DupDef/Dd2.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./DupDef/Dd2.hs"]
getModuleGhc "./DupDef/Dd1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "DupDef.Dd1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg), _s) <- ct $ runRefactGhc comp [Left "DupDef/Dd2.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"DupDef.Dd1\",\"DupDef.Dd1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[DupDef.Dd2, DupDef.Dd3]"
-- -------------------------------------------------------------------
describe "runRefactGhc" $ do
it "contains a State monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (_,s) <- runRefactGhcState comp
(_,s) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
(rsUniqState s) `shouldBe` 100
it "contains the GhcT monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (r,_) <- runRefactGhcState comp
(r,_) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
r `shouldBe` ("[\"TypeUtils.B ( TypeUtils/B.hs, nothing )\","
++"\"TypeUtils.C ( TypeUtils/C.hs, nothing )\"]")
-- -------------------------------------------------------------------
describe "RefactFlags" $ do
it "puts the RefactDone flag through its paces" $ do
(t,_toks,tgt) <- ct $ parsedFileGhc "./FreeAndDeclared/DeclareTypes.hs"
let
comp = do
v1 <- getRefactDone
clearRefactDone
v2 <- getRefactDone
setRefactDone
v3 <- getRefactDone
return (v1,v2,v3)
-- ((v1',v2',v3'), _s) <- runRefactGhcState comp
((v1',v2',v3'), _s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(show (v1',v2',v3')) `shouldBe` "(False,False,True)"
-- ---------------------------------------------------------------------
-- Helper functions
-- bFileName :: GHC.FastString
-- bFileName = GHC.mkFastString "./test/testdata/TypeUtils/B.hs"
-- parsedFileBGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileBGhc = ct $ parsedFileGhc "./TypeUtils/B.hs"
-- parsedFileMGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileMGhc = parsedFileGhc "./test/testdata/M.hs"
-- parseFileBGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileBGhc = parseSourceFileTest fileName
-- where
-- fileName = "./test/testdata/TypeUtils/B.hs"
-- parseFileMGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileMGhc = parseSourceFileTest fileName
-- where
-- fileName = "./M.hs" | 22,815 | spec = do
describe "locToExp on ParsedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,43) parsed :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
it "finds the largest leftmost expression contained in a given region #2" $ do
-- ((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just expr) = locToExp (7,7) (7,41) modu :: Maybe (GHC.Located (GHC.HsExpr GHC.RdrName))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
it "finds the largest leftmost expression in RenamedSource" $ do
-- ((_, renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,41) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,12)
getLocatedEnd expr `shouldBe` (7,19)
describe "locToExp on RenamedSource" $ do
it "finds the largest leftmost expression contained in a given region #1" $ do
-- ((_, Just renamed, _), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let renamed = fromJust $ GHC.tm_renamed_source t
let (Just expr) = locToExp (7,7) (7,43) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
getLocatedStart expr `shouldBe` (7,9)
getLocatedEnd expr `shouldBe` (7,42)
-- -------------------------------------------------------------------
describe "loading a file" $ do
it "loads a file having the LANGUAGE CPP pragma" $ do
(_t, toks,_) <- ct $ parsedFileGhc "./BCpp.hs"
-- let renamed = fromJust $ GHC.tm_renamed_source t
-- let (Just expr) = locToExp (6,1) (12,1) renamed :: Maybe (GHC.Located (GHC.HsExpr GHC.Name))
origStr <- readFile "./test/testdata/BCpp.hs"
let toksStr = (GHC.showRichTokenStream toks)
-- (show (filter (\(c,_) -> c /= B) $ getGroupedDiff (lines toksStr) (lines origStr))) `shouldBe` "[]"
(show $ compareStrings toksStr origStr) `shouldBe` "[]"
-- -----------------------------------
it "loads a series of files based on cabal1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal1"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
let settings = defaultSettings { rsetEnabledTargets = (True,True,False,False)
-- , rsetVerboseLevel = Debug
}
r <- rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)
-- r <- rename logTestSettings cradle "./src/Foo/Bar.hs" "baz1" (3, 1)
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","
++"\"test/testdata/cabal/cabal1/src/main.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal2, which has 2 exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal1"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/Foo/Bar.hs" "baz1" (3, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/Foo/Bar.hs\","++
"\"test/testdata/cabal/cabal2/src/main1.hs\","++
"\"test/testdata/cabal/cabal2/src/main2.hs\"]"
-- -----------------------------------
it "loads a series of files based on cabal3, which has a lib and an exe" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal3"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal3"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings testOptions "./src/main1.hs" "baz1" (7, 1)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe` "[\"./src/main1.hs\"]"
-- -----------------------------------
{- TODO: this test fails on travis, due to missing hspec-discover
it "renames in HaRe Utils 1" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./src/Language/Haskell/Refact/Utils.hs" "clientModsAndFiles1" (473, 6)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
it "renames in HaRe Utils 2" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
, rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 10)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"./src/Language/Haskell/Refact/Utils.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\","++
"\"test/UtilsSpec.hs\","++
"\"./src/Language/Haskell/Refact/Renaming.hs\","++
"\"./src/Language/Haskell/Refact/MoveDef.hs\","++
"\"./src/Language/Haskell/Refact/DupDef.hs\"]"
-}
-- -----------------------------------
{-
-- This test does not work properly on Travis, missing hspec-discover
it "renames in HaRe Utils 3" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
let settings = defaultSettings { rsetEnabledTargets = (True,True,True,True)
-- , rsetVerboseLevel = Debug
}
let handler = [Handler handler1]
handler1 :: GHC.SourceError -> IO [String]
handler1 e = do
setCurrentDirectory currentDir
return [show e]
r <- catches (rename settings cradle "./test/UtilsSpec.hs" "parsed" (41, 11)) handler
setCurrentDirectory currentDir
r' <- mapM makeRelativeToCurrentDirectory r
(show r') `shouldBe`
"[\"test/UtilsSpec.hs\"]"
-}
-- -------------------------------------------------------------------
describe "sameOccurrence" $ do
it "checks that a given syntax element is the same occurrence as another" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "isVarId" $ do
it "returns True if a string is a lexically valid variable name" $ do
isVarId "foo" `shouldBe` True
it "returns False if a string is not lexically valid variable name" $ do
isVarId "Foo" `shouldBe` False
-- -------------------------------------------------------------------
describe "getModuleName" $ do
it "returns a string for the module name if there is one" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileBGhc
(t, _toks,_) <- ct $ parsedFileGhc "./TypeUtils/B.hs"
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
let (Just (_modname,modNameStr)) = getModuleName modu
-- let modNameStr = "foo"
modNameStr `shouldBe` "TypeUtils.B"
it "returns Nothing for the module name otherwise" $ do
-- modInfo@((_, _, mod), toks) <- parsedFileNoMod
(t, _toks,_) <- parsedFileNoMod
let modu = GHC.pm_parsed_source $ GHC.tm_parsed_module t
getModuleName modu `shouldBe` Nothing
-- -------------------------------------------------------------------
describe "modIsExported" $ do
it "needs a test or two" $ do
pending -- "write this test"
-- -------------------------------------------------------------------
describe "clientModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
------------------------------------
it "gets modules which directly or indirectly import a module #1" $ do
-- TODO: harvest this commonality
-- (t, toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./M3.hs"
getModuleGhc "./S1.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialLogOnState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
------------------------------------
it "gets modules which directly or indirectly import a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseSourceFileTest "./M.hs" -- Load the main file first
-- loadModuleGraphGhc $ Just ["./M.hs"]
getModuleGhc "./M3.hs"
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "M3"
g <- clientModsAndFiles tm
return g
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main]"
------------------------------------
it "gets modules which import a module in different cabal targets" $ do
currentDir <- getCurrentDirectory
-- currentDir `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe"
setCurrentDirectory "./test/testdata/cabal/cabal2"
-- d <- getCurrentDirectory
-- d `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
-- cradle <- findCradle
-- (show cradle) `shouldBe` ""
-- (cradleCurrentDir cradle) `shouldBe` "/home/alanz/mysrc/github/alanz/HaRe/test/testdata/cabal/cabal2"
let
comp = do
initGhcSession [Left "./src/main1.hs"]
getModuleGhc "./src/Foo/Bar.hs" -- Load the file first
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "Foo.Bar"
g <- clientModsAndFiles tm
return g
-- (mg,_s) <- runRefactGhcState comp
-- (mg,_s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(mg,_s) <- runRefactGhc comp [Left "./src/main1.hs"] (initialState { rsModule = Nothing }) testOptions
showGhc (map GM.mpModule mg) `shouldBe` "[Main, Main]"
setCurrentDirectory currentDir
-- -------------------------------------------------------------------
describe "serverModsAndFiles" $ do
it "can only be called in a live RefactGhc session" $ do
pending -- "write this test"
it "gets modules which are directly or indirectly imported by a module #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "S1"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
-- (mg,_s) <- ct $ runRefactGhc comp tgt (initialLogOnState { rsModule = initRefactModule t }) testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[]"
it "gets modules which are directly or indirectly imported by a module #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M3.hs"
let
comp = do
-- (_p,_toks) <- parseFileMGhc -- Load the main file first
g <- serverModsAndFiles $ GHC.mkModuleName "M3"
return g
-- (mg,_s) <- ct $ runRefactGhcState comp
(mg,_s) <- ct $ runRefactGhc comp [Left "./M3.hs"] initialState testOptions
showGhc (map GHC.ms_mod mg) `shouldBe` "[M2, S1]"
-- -------------------------------------------------------------------
{-
describe "getCurrentModuleGraph" $ do
it "gets the module graph for the currently loaded modules" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- getCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
map (\m -> GHC.moduleNameString $ GHC.ms_mod_name m) mg `shouldBe` (["TypeUtils.B","TypeUtils.C"])
map (\m -> show $ GHC.ml_hs_file $ GHC.ms_location m) mg `shouldBe` (["Just \"./test/testdata/TypeUtils/B.hs\""
,"Just \"./test/testdata/TypeUtils/C.hs\""])
it "gets the updated graph, after a refactor" $ do
pending -- "write this test"
-}
-- -------------------------------------------------------------------
{-
describe "sortCurrentModuleGraph" $ do
it "needs a test or two" $ do
let
comp = do
(_p,_toks) <- parseFileBGhc -- Load the file first
g <- sortCurrentModuleGraph
return g
(mg,_s) <- runRefactGhcState comp
(showGhc $ map (\m -> GHC.ms_mod m) (GHC.flattenSCCs mg)) `shouldBe` "[main:TypeUtils.C, main:TypeUtils.B]"
-}
-- -------------------------------------------------------------------
describe "getModuleGhc" $ do
it "retrieves a module from an existing module graph #1" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./M.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./M.hs"]
-- getModuleGhc "./test/testdata/S1.hs"
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
( (t, mg), _s) <- ct $ runRefactGhc comp [Left "./M.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "loads the module and dependents if no existing module graph" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./S1.hs"
let
comp = do
getModuleGhc "./S1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "S1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg ), _s) <- ct $ runRefactGhc comp [Left "./S1.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"S1\",\"S1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[Main, M3, M2]"
-- ---------------------------------
it "retrieves a module from an existing module graph #2" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/DupDef/Dd2.hs"
let
comp = do
-- loadModuleGraphGhc $ Just ["./DupDef/Dd2.hs"]
getModuleGhc "./DupDef/Dd1.hs"
pr <- getTypecheckedModule
tm <- getRefactTargetModule
-- g <- clientModsAndFiles $ GHC.mkModuleName "DupDef.Dd1"
g <- clientModsAndFiles tm
return (pr,g)
((t, mg), _s) <- ct $ runRefactGhc comp [Left "DupDef/Dd2.hs"] initialState testOptions
let parsed = GHC.pm_parsed_source $ GHC.tm_parsed_module t
(show $ getModuleName parsed) `shouldBe` "Just (ModuleName \"DupDef.Dd1\",\"DupDef.Dd1\")"
showGhc (map GM.mpModule mg) `shouldBe` "[DupDef.Dd2, DupDef.Dd3]"
-- -------------------------------------------------------------------
describe "runRefactGhc" $ do
it "contains a State monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (_,s) <- runRefactGhcState comp
(_,s) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
(rsUniqState s) `shouldBe` 100
it "contains the GhcT monad" $ do
-- (t,toks,tgt) <- ct $ parsedFileGhc "./test/testdata/TypeUtils/B.hs"
let
comp = do
s <- get
-- (_t, _toks) <- parseSourceFileTest "./test/testdata/TypeUtils/B.hs"
g <- GHC.getModuleGraph
gs <- mapM GHC.showModule g
-- GHC.liftIO (putStrLn $ "modulegraph=" ++ (show gs))
put (s {rsUniqState = 100})
return (show gs)
-- (r,_) <- runRefactGhcState comp
(r,_) <- ct $ runRefactGhc comp [Left "TypeUtils/B.hs"] (initialState { rsModule = Nothing }) testOptions
r `shouldBe` ("[\"TypeUtils.B ( TypeUtils/B.hs, nothing )\","
++"\"TypeUtils.C ( TypeUtils/C.hs, nothing )\"]")
-- -------------------------------------------------------------------
describe "RefactFlags" $ do
it "puts the RefactDone flag through its paces" $ do
(t,_toks,tgt) <- ct $ parsedFileGhc "./FreeAndDeclared/DeclareTypes.hs"
let
comp = do
v1 <- getRefactDone
clearRefactDone
v2 <- getRefactDone
setRefactDone
v3 <- getRefactDone
return (v1,v2,v3)
-- ((v1',v2',v3'), _s) <- runRefactGhcState comp
((v1',v2',v3'), _s) <- runRefactGhc comp tgt (initialState { rsModule = initRefactModule t }) testOptions
(show (v1',v2',v3')) `shouldBe` "(False,False,True)"
-- ---------------------------------------------------------------------
-- Helper functions
-- bFileName :: GHC.FastString
-- bFileName = GHC.mkFastString "./test/testdata/TypeUtils/B.hs"
-- parsedFileBGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileBGhc = ct $ parsedFileGhc "./TypeUtils/B.hs"
-- parsedFileMGhc :: IO (ParseResult,[PosToken],Targets)
-- parsedFileMGhc = parsedFileGhc "./test/testdata/M.hs"
-- parseFileBGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileBGhc = parseSourceFileTest fileName
-- where
-- fileName = "./test/testdata/TypeUtils/B.hs"
-- parseFileMGhc :: RefactGhc (ParseResult, [PosToken],Targets)
-- parseFileMGhc = parseSourceFileTest fileName
-- where
-- fileName = "./M.hs" | 22,802 | false | true | 96 | 25 | 5,738 | 2,910 | 1,524 | 1,386 | null | null |
wkoiking/fieldequip | src/Core/Interval.hs | bsd-3-clause | joinIntervals :: (Eq a, Monoid a) => [Interval a] -> [Interval a]
joinIntervals = sanitize . foldr joinInterval [] . sortBy (comparing fst) | 139 | joinIntervals :: (Eq a, Monoid a) => [Interval a] -> [Interval a]
joinIntervals = sanitize . foldr joinInterval [] . sortBy (comparing fst) | 139 | joinIntervals = sanitize . foldr joinInterval [] . sortBy (comparing fst) | 73 | false | true | 0 | 10 | 22 | 72 | 34 | 38 | null | null |
wskplho/stack | src/Stack/Options.hs | bsd-3-clause | initOptsParser :: Parser InitOpts
initOptsParser =
InitOpts <$> method <*> overwrite <*> fmap not ignoreSubDirs
where
ignoreSubDirs = flag False
True
(long "ignore-subdirs" <>
help "Do not search for .cabal files in sub directories")
overwrite = flag False
True
(long "force" <>
help "Force overwriting of an existing stack.yaml if it exists")
method = solver
<|> (MethodResolver <$> resolver)
<|> (MethodSnapshot <$> snapPref)
solver =
flag' MethodSolver
(long "solver" <>
help "Use a dependency solver to determine dependencies")
snapPref =
flag' PrefLTS
(long "prefer-lts" <>
help "Prefer LTS snapshots over Nightly snapshots") <|>
flag' PrefNightly
(long "prefer-nightly" <>
help "Prefer Nightly snapshots over LTS snapshots") <|>
pure PrefNone
resolver = option readAbstractResolver
(long "resolver" <>
metavar "RESOLVER" <>
help "Use the given resolver, even if not all dependencies are met")
-- | Parse for a logging level. | 1,254 | initOptsParser :: Parser InitOpts
initOptsParser =
InitOpts <$> method <*> overwrite <*> fmap not ignoreSubDirs
where
ignoreSubDirs = flag False
True
(long "ignore-subdirs" <>
help "Do not search for .cabal files in sub directories")
overwrite = flag False
True
(long "force" <>
help "Force overwriting of an existing stack.yaml if it exists")
method = solver
<|> (MethodResolver <$> resolver)
<|> (MethodSnapshot <$> snapPref)
solver =
flag' MethodSolver
(long "solver" <>
help "Use a dependency solver to determine dependencies")
snapPref =
flag' PrefLTS
(long "prefer-lts" <>
help "Prefer LTS snapshots over Nightly snapshots") <|>
flag' PrefNightly
(long "prefer-nightly" <>
help "Prefer Nightly snapshots over LTS snapshots") <|>
pure PrefNone
resolver = option readAbstractResolver
(long "resolver" <>
metavar "RESOLVER" <>
help "Use the given resolver, even if not all dependencies are met")
-- | Parse for a logging level. | 1,254 | initOptsParser =
InitOpts <$> method <*> overwrite <*> fmap not ignoreSubDirs
where
ignoreSubDirs = flag False
True
(long "ignore-subdirs" <>
help "Do not search for .cabal files in sub directories")
overwrite = flag False
True
(long "force" <>
help "Force overwriting of an existing stack.yaml if it exists")
method = solver
<|> (MethodResolver <$> resolver)
<|> (MethodSnapshot <$> snapPref)
solver =
flag' MethodSolver
(long "solver" <>
help "Use a dependency solver to determine dependencies")
snapPref =
flag' PrefLTS
(long "prefer-lts" <>
help "Prefer LTS snapshots over Nightly snapshots") <|>
flag' PrefNightly
(long "prefer-nightly" <>
help "Prefer Nightly snapshots over LTS snapshots") <|>
pure PrefNone
resolver = option readAbstractResolver
(long "resolver" <>
metavar "RESOLVER" <>
help "Use the given resolver, even if not all dependencies are met")
-- | Parse for a logging level. | 1,220 | false | true | 0 | 10 | 460 | 217 | 105 | 112 | null | null |
machine-intelligence/Botworld | ct2hs.hs | bsd-3-clause | name :: Parser Name
name = (:) <$> satisfy isAlpha_ <*> many (satisfy isAlphaNum_) where
isAlpha_ = (||) <$> isAlpha <*> (== '_')
isAlphaNum_ = (||) <$> isAlphaNum <*> (== '_') | 180 | name :: Parser Name
name = (:) <$> satisfy isAlpha_ <*> many (satisfy isAlphaNum_) where
isAlpha_ = (||) <$> isAlpha <*> (== '_')
isAlphaNum_ = (||) <$> isAlphaNum <*> (== '_') | 180 | name = (:) <$> satisfy isAlpha_ <*> many (satisfy isAlphaNum_) where
isAlpha_ = (||) <$> isAlpha <*> (== '_')
isAlphaNum_ = (||) <$> isAlphaNum <*> (== '_') | 160 | false | true | 0 | 8 | 34 | 76 | 43 | 33 | null | null |
eklavya/Idris-dev | src/Idris/Docs.hs | bsd-3-clause | showDoc ist d
| nullDocstring d = empty
| otherwise = text " -- " <>
renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) d | 173 | showDoc ist d
| nullDocstring d = empty
| otherwise = text " -- " <>
renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) d | 173 | showDoc ist d
| nullDocstring d = empty
| otherwise = text " -- " <>
renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) d | 173 | false | false | 0 | 12 | 45 | 77 | 34 | 43 | null | null |
kig/tomtegebra | Tomtegebra/VBO.hs | gpl-3.0 | -- | Creates a 'BufferObject' for the given list of 'Storable' elements.
--
-- E.g. @my_vbo \<- createVBO [1,2,3,4::GLfloat]@
createVBO :: Storable a => [a] -> IO BufferObject
createVBO elems = do
[vbo] <- genObjectNames 1
bindBuffer ArrayBuffer $= Just vbo
arr <- newListArray (0, length elems - 1) elems -- Data.Array.MArray
withStorableArray arr (\ptr -> -- Data.Array.Storable
bufferData ArrayBuffer $= (ptrsize elems, ptr, StaticDraw))
bindBuffer ArrayBuffer $= Nothing
reportErrors
return vbo
where ptrsize [] = toEnum 0
ptrsize (x:_) = toEnum $ length elems * (sizeOf x) | 646 | createVBO :: Storable a => [a] -> IO BufferObject
createVBO elems = do
[vbo] <- genObjectNames 1
bindBuffer ArrayBuffer $= Just vbo
arr <- newListArray (0, length elems - 1) elems -- Data.Array.MArray
withStorableArray arr (\ptr -> -- Data.Array.Storable
bufferData ArrayBuffer $= (ptrsize elems, ptr, StaticDraw))
bindBuffer ArrayBuffer $= Nothing
reportErrors
return vbo
where ptrsize [] = toEnum 0
ptrsize (x:_) = toEnum $ length elems * (sizeOf x) | 518 | createVBO elems = do
[vbo] <- genObjectNames 1
bindBuffer ArrayBuffer $= Just vbo
arr <- newListArray (0, length elems - 1) elems -- Data.Array.MArray
withStorableArray arr (\ptr -> -- Data.Array.Storable
bufferData ArrayBuffer $= (ptrsize elems, ptr, StaticDraw))
bindBuffer ArrayBuffer $= Nothing
reportErrors
return vbo
where ptrsize [] = toEnum 0
ptrsize (x:_) = toEnum $ length elems * (sizeOf x) | 468 | true | true | 0 | 12 | 156 | 188 | 91 | 97 | null | null |
nirvinm/Solving-Exercises-in-Haskell-Programming-From-First-Principles | Algebraic_DataTypes/PhoneExercise.hs | gpl-3.0 | mapAlphabetToButton :: Alphabet -> (Digit, [Alphabet])
mapAlphabetToButton a =
case find (\(_, as) -> elem (toLower a) as) keypad of
Just k -> k
_ -> undefined | 179 | mapAlphabetToButton :: Alphabet -> (Digit, [Alphabet])
mapAlphabetToButton a =
case find (\(_, as) -> elem (toLower a) as) keypad of
Just k -> k
_ -> undefined | 179 | mapAlphabetToButton a =
case find (\(_, as) -> elem (toLower a) as) keypad of
Just k -> k
_ -> undefined | 124 | false | true | 0 | 11 | 46 | 76 | 40 | 36 | null | null |
ocharles/opaleye-tf | src/Opaleye/TF/Text.hs | bsd-3-clause | chr :: Expr s 'PGInteger -> Expr s 'PGText
chr (Expr a) = Expr (Op.FunExpr "chr" [a]) | 85 | chr :: Expr s 'PGInteger -> Expr s 'PGText
chr (Expr a) = Expr (Op.FunExpr "chr" [a]) | 85 | chr (Expr a) = Expr (Op.FunExpr "chr" [a]) | 42 | false | true | 0 | 8 | 16 | 58 | 27 | 31 | null | null |
christiaanb/ghc | compiler/typecheck/TcType.hs | bsd-3-clause | metaTyVarInfo :: TcTyVar -> MetaInfo
metaTyVarInfo tv
= ASSERT( isTcTyVar tv )
case tcTyVarDetails tv of
MetaTv { mtv_info = info } -> info
_ -> pprPanic "metaTyVarInfo" (ppr tv) | 196 | metaTyVarInfo :: TcTyVar -> MetaInfo
metaTyVarInfo tv
= ASSERT( isTcTyVar tv )
case tcTyVarDetails tv of
MetaTv { mtv_info = info } -> info
_ -> pprPanic "metaTyVarInfo" (ppr tv) | 196 | metaTyVarInfo tv
= ASSERT( isTcTyVar tv )
case tcTyVarDetails tv of
MetaTv { mtv_info = info } -> info
_ -> pprPanic "metaTyVarInfo" (ppr tv) | 159 | false | true | 0 | 11 | 47 | 68 | 33 | 35 | null | null |
kyren/hsgb | lib/Gameboy/Instructions.hs | unlicense | encodeInstruction DEC_SP = [0x3b] | 33 | encodeInstruction DEC_SP = [0x3b] | 33 | encodeInstruction DEC_SP = [0x3b] | 33 | false | false | 1 | 5 | 3 | 15 | 6 | 9 | null | null |
comius/haskell-mpfr | src/Numeric/Rounded/Interval.hs | lgpl-3.0 | {-
-- | Deflate an interval by shrinking it from both ends.
--
-- >>> deflate 3.0 (-4.0 ... 10.0)
-- -1.0 ... 7.0
--
-- >>> deflate 2.0 (-1.0 ... 1.0)
-- Empty
--
-- >>> deflate 1.0 empty
-- Empty
deflate :: => a -> Interval a -> Interval a
deflate _ Empty = Empty
deflate x (I a b) | a' <= b' = I a' b'
| otherwise = Empty
where
a' = a + x
b' = b - x
-}
-- | For all @x@ in @X@, @y@ in @Y@. @x '<' y@
--
-- >>> (5 ... 10 :: Interval Double) <! (20 ... 30 :: Interval Double)
-- True
--
-- >>> (5 ... 10 :: Interval Double) <! (10 ... 30 :: Interval Double)
-- False
--
-- >>> (20 ... 30 :: Interval Double) <! (5 ... 10 :: Interval Double)
-- False
(<!) :: Precision p => Interval p -> Interval p -> Bool
I _ bx <! I ay _ = coerce bx < ay | 786 | (<!) :: Precision p => Interval p -> Interval p -> Bool
I _ bx <! I ay _ = coerce bx < ay | 90 | I _ bx <! I ay _ = coerce bx < ay | 33 | true | true | 2 | 10 | 223 | 73 | 38 | 35 | null | null |
chwthewke/horbits | testsuite/Horbits/KerbalDateTimeTest.hs | bsd-3-clause | prop_ModifyingIntegralComponentVariesDurationBySameAmount :: Property
prop_ModifyingIntegralComponentVariesDurationBySameAmount =
forAll ((,,) <$> genKerbalTime <*> elements integralComponentWeights <*> arbitrary) $
uncurry3 checkModifyingIntegralComponentVariesDurationAccordingToWeight
where uncurry3 f (a, b, c) = f a b c | 338 | prop_ModifyingIntegralComponentVariesDurationBySameAmount :: Property
prop_ModifyingIntegralComponentVariesDurationBySameAmount =
forAll ((,,) <$> genKerbalTime <*> elements integralComponentWeights <*> arbitrary) $
uncurry3 checkModifyingIntegralComponentVariesDurationAccordingToWeight
where uncurry3 f (a, b, c) = f a b c | 338 | prop_ModifyingIntegralComponentVariesDurationBySameAmount =
forAll ((,,) <$> genKerbalTime <*> elements integralComponentWeights <*> arbitrary) $
uncurry3 checkModifyingIntegralComponentVariesDurationAccordingToWeight
where uncurry3 f (a, b, c) = f a b c | 268 | false | true | 0 | 11 | 41 | 71 | 37 | 34 | null | null |
mbrock/HBEAM | src/Language/Erlang/BEAM/Emulator.hs | gpl-3.0 | getStack :: Int -> Emulation EValue
getStack i = do p <- asks emuProcess
liftIO $ do
stack <- readIORef (procStack p)
sp <- readIORef (procSP p)
readArray stack (sp - i) | 239 | getStack :: Int -> Emulation EValue
getStack i = do p <- asks emuProcess
liftIO $ do
stack <- readIORef (procStack p)
sp <- readIORef (procSP p)
readArray stack (sp - i) | 239 | getStack i = do p <- asks emuProcess
liftIO $ do
stack <- readIORef (procStack p)
sp <- readIORef (procSP p)
readArray stack (sp - i) | 203 | false | true | 0 | 13 | 101 | 85 | 38 | 47 | null | null |
brendanhay/gogol | gogol-servicemanagement/gen/Network/Google/ServiceManagement/Types/Product.hs | mpl-2.0 | -- | Percentage of completion of this operation, ranging from 0 to 100.
omProgressPercentage :: Lens' OperationMetadata (Maybe Int32)
omProgressPercentage
= lens _omProgressPercentage
(\ s a -> s{_omProgressPercentage = a})
. mapping _Coerce | 255 | omProgressPercentage :: Lens' OperationMetadata (Maybe Int32)
omProgressPercentage
= lens _omProgressPercentage
(\ s a -> s{_omProgressPercentage = a})
. mapping _Coerce | 183 | omProgressPercentage
= lens _omProgressPercentage
(\ s a -> s{_omProgressPercentage = a})
. mapping _Coerce | 121 | true | true | 0 | 10 | 46 | 55 | 28 | 27 | null | null |
m-lopez/jack | src/Repl/Repl.hs | mit | -- | Prints a definition.
showDef :: (ExprName, QType, Expr) -> String
showDef (ExprName s, t, e) =
"defined " ++ show s ++ ": " ++ show t ++ " := " ++ show e | 160 | showDef :: (ExprName, QType, Expr) -> String
showDef (ExprName s, t, e) =
"defined " ++ show s ++ ": " ++ show t ++ " := " ++ show e | 134 | showDef (ExprName s, t, e) =
"defined " ++ show s ++ ": " ++ show t ++ " := " ++ show e | 89 | true | true | 0 | 10 | 37 | 73 | 37 | 36 | null | null |
kishoredbn/barrelfish | tools/flounder/MsgFragments.hs | mit | bitsizeof_builtin _ ErrVal = 32 | 31 | bitsizeof_builtin _ ErrVal = 32 | 31 | bitsizeof_builtin _ ErrVal = 32 | 31 | false | false | 0 | 5 | 4 | 11 | 5 | 6 | null | null |
pacak/cuddly-bassoon | hashable-1.2.6.0/Data/Hashable/SipHash.hs | bsd-3-clause | finalize :: Int -> (Word64 -> r) -> Sip -> r
finalize d k st@Sip{..}
| d == 4 = sipRound (sipRound (sipRound (sipRound k'))) st'
| otherwise = runRounds d k' st'
where k' Sip{..} = k $! v0 `xor` v1 `xor` v2 `xor` v3
st' = st{ v2 = v2 `xor` 0xff }
| 275 | finalize :: Int -> (Word64 -> r) -> Sip -> r
finalize d k st@Sip{..}
| d == 4 = sipRound (sipRound (sipRound (sipRound k'))) st'
| otherwise = runRounds d k' st'
where k' Sip{..} = k $! v0 `xor` v1 `xor` v2 `xor` v3
st' = st{ v2 = v2 `xor` 0xff }
| 275 | finalize d k st@Sip{..}
| d == 4 = sipRound (sipRound (sipRound (sipRound k'))) st'
| otherwise = runRounds d k' st'
where k' Sip{..} = k $! v0 `xor` v1 `xor` v2 `xor` v3
st' = st{ v2 = v2 `xor` 0xff }
| 230 | false | true | 2 | 12 | 83 | 152 | 80 | 72 | null | null |
ssanj/YorgeyCourse | src/Chapter2/LogAnalysis.hs | mit | isNumeric :: String -> Bool
isNumeric [] = False | 48 | isNumeric :: String -> Bool
isNumeric [] = False | 48 | isNumeric [] = False | 20 | false | true | 0 | 6 | 8 | 20 | 10 | 10 | null | null |
ddssff/process-listlike-old | System/Process/ListLike/Chunks.hs | mit | -- | Based on the 'ExitCode', either return a Result Chunk or throw an
-- IO error similar to what 'System.Process.readProcess' would have
-- thrown.
throwProcessResult :: String -> String -> ExitCode -> IO (Chunk a)
throwProcessResult _ _ ExitSuccess = return $ Result ExitSuccess | 281 | throwProcessResult :: String -> String -> ExitCode -> IO (Chunk a)
throwProcessResult _ _ ExitSuccess = return $ Result ExitSuccess | 131 | throwProcessResult _ _ ExitSuccess = return $ Result ExitSuccess | 64 | true | true | 0 | 10 | 44 | 49 | 25 | 24 | null | null |
shmookey/bc-tools | src/Munt/App.hs | bsd-3-clause | stdout :: Sink B8.ByteString IO ()
stdout = CL.mapM_ B8.putStr | 62 | stdout :: Sink B8.ByteString IO ()
stdout = CL.mapM_ B8.putStr | 62 | stdout = CL.mapM_ B8.putStr | 27 | false | true | 1 | 6 | 9 | 35 | 14 | 21 | null | null |
urbanslug/ghc | compiler/types/TyCon.hs | bsd-3-clause | -- | Extract an 'AlgTyConRhs' with information about data constructors from an
-- algebraic or tuple 'TyCon'. Panics for any other sort of 'TyCon'
algTyConRhs :: TyCon -> AlgTyConRhs
algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs | 228 | algTyConRhs :: TyCon -> AlgTyConRhs
algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs | 81 | algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs | 45 | true | true | 3 | 7 | 35 | 39 | 19 | 20 | null | null |
sopvop/snap-server | test/Snap/Internal/Http/Server/Session/Tests.hs | bsd-3-clause | testWeirdMissingSlash :: Test
testWeirdMissingSlash = testCase "session/weirdMissingSlash" $ do
do
let req = "GET foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "missing slash" $ expected1 `S.isSuffixOf` out
do
let req = "GET /foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "with slash" $ expected2 `S.isSuffixOf` out
where
expected1 = S.concat [ "\r\n\r\n"
, "foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
expected2 = S.concat [ "\r\n\r\n"
, "/foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
p s = writeBuilder $ byteString s `mappend` char8 '\n'
snap = do
rq <- getRequest
p $ rqURI rq
p $ rqPathInfo rq
p $ rqQueryString rq
------------------------------------------------------------------------------ | 1,020 | testWeirdMissingSlash :: Test
testWeirdMissingSlash = testCase "session/weirdMissingSlash" $ do
do
let req = "GET foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "missing slash" $ expected1 `S.isSuffixOf` out
do
let req = "GET /foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "with slash" $ expected2 `S.isSuffixOf` out
where
expected1 = S.concat [ "\r\n\r\n"
, "foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
expected2 = S.concat [ "\r\n\r\n"
, "/foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
p s = writeBuilder $ byteString s `mappend` char8 '\n'
snap = do
rq <- getRequest
p $ rqURI rq
p $ rqPathInfo rq
p $ rqQueryString rq
------------------------------------------------------------------------------ | 1,020 | testWeirdMissingSlash = testCase "session/weirdMissingSlash" $ do
do
let req = "GET foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "missing slash" $ expected1 `S.isSuffixOf` out
do
let req = "GET /foo/bar?z HTTP/1.0\r\n\r\n"
out <- getSessionOutput [req] snap
assertBool "with slash" $ expected2 `S.isSuffixOf` out
where
expected1 = S.concat [ "\r\n\r\n"
, "foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
expected2 = S.concat [ "\r\n\r\n"
, "/foo/bar?z\n"
, "foo/bar\n"
, "z\n"
]
p s = writeBuilder $ byteString s `mappend` char8 '\n'
snap = do
rq <- getRequest
p $ rqURI rq
p $ rqPathInfo rq
p $ rqQueryString rq
------------------------------------------------------------------------------ | 990 | false | true | 0 | 16 | 381 | 226 | 109 | 117 | null | null |
shlevy/ghc | compiler/basicTypes/VarEnv.hs | bsd-3-clause | emptyDVarEnv :: DVarEnv a
emptyDVarEnv = emptyUDFM | 50 | emptyDVarEnv :: DVarEnv a
emptyDVarEnv = emptyUDFM | 50 | emptyDVarEnv = emptyUDFM | 24 | false | true | 0 | 5 | 6 | 14 | 7 | 7 | null | null |
ocramz/monad-bayes | models/HMM.hs | mit | scores :: [Vector Double]
scores = map (\y -> fromList $ map (fromLogDomain . (\x -> pdf (emission x) y)) states) values | 120 | scores :: [Vector Double]
scores = map (\y -> fromList $ map (fromLogDomain . (\x -> pdf (emission x) y)) states) values | 120 | scores = map (\y -> fromList $ map (fromLogDomain . (\x -> pdf (emission x) y)) states) values | 94 | false | true | 0 | 16 | 21 | 72 | 35 | 37 | null | null |
hvr/jhc | src/Info/Binary.hs | mit | cb n x = (n, Binable x, typeOf x) | 33 | cb n x = (n, Binable x, typeOf x) | 33 | cb n x = (n, Binable x, typeOf x) | 33 | false | false | 0 | 6 | 8 | 27 | 13 | 14 | null | null |
Kludgy/hdevtools | src/CommandLoop.hs | mit | logAction :: IORef State -> ClientSend -> GHC.DynFlags -> GHC.Severity -> GHC.SrcSpan -> Outputable.PprStyle -> ErrUtils.MsgDoc -> IO ()
logAction state clientSend dflags severity srcspan style msg =
let out = Outputable.renderWithStyle dflags fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage severity srcspan msg
#else
logAction :: IORef State -> ClientSend -> GHC.Severity -> GHC.SrcSpan -> Outputable.PprStyle -> ErrUtils.Message -> IO ()
logAction state clientSend severity srcspan style msg =
let out = Outputable.renderWithStyle fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage srcspan msg
#endif | 768 | logAction :: IORef State -> ClientSend -> GHC.DynFlags -> GHC.Severity -> GHC.SrcSpan -> Outputable.PprStyle -> ErrUtils.MsgDoc -> IO ()
logAction state clientSend dflags severity srcspan style msg =
let out = Outputable.renderWithStyle dflags fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage severity srcspan msg
#else
logAction :: IORef State -> ClientSend -> GHC.Severity -> GHC.SrcSpan -> Outputable.PprStyle -> ErrUtils.Message -> IO ()
logAction state clientSend severity srcspan style msg =
let out = Outputable.renderWithStyle fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage srcspan msg
#endif | 768 | logAction state clientSend dflags severity srcspan style msg =
let out = Outputable.renderWithStyle dflags fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage severity srcspan msg
#else
logAction :: IORef State -> ClientSend -> GHC.Severity -> GHC.SrcSpan -> Outputable.PprStyle -> ErrUtils.Message -> IO ()
logAction state clientSend severity srcspan style msg =
let out = Outputable.renderWithStyle fullMsg style
_ = severity
in logActionSend state clientSend severity out
where fullMsg = ErrUtils.mkLocMessage srcspan msg
#endif | 631 | false | true | 0 | 14 | 138 | 128 | 61 | 67 | null | null |
JJ/linguist | samples/Haskell/maze-solving.hs | mit | solve' maze pos@(x, y) prevPos =
let newPositions = [(x, y - 2), (x + 4, y), (x, y + 2), (x - 4, y)]
notPrev pos' = pos' /= prevPos
newPositions' = filter notPrev newPositions
wallPositions = map (average pos) newPositions'
zipped = zip newPositions' wallPositions
legalMoves = filter (notBlocked maze) zipped
in tryMoves maze pos legalMoves | 375 | solve' maze pos@(x, y) prevPos =
let newPositions = [(x, y - 2), (x + 4, y), (x, y + 2), (x - 4, y)]
notPrev pos' = pos' /= prevPos
newPositions' = filter notPrev newPositions
wallPositions = map (average pos) newPositions'
zipped = zip newPositions' wallPositions
legalMoves = filter (notBlocked maze) zipped
in tryMoves maze pos legalMoves | 375 | solve' maze pos@(x, y) prevPos =
let newPositions = [(x, y - 2), (x + 4, y), (x, y + 2), (x - 4, y)]
notPrev pos' = pos' /= prevPos
newPositions' = filter notPrev newPositions
wallPositions = map (average pos) newPositions'
zipped = zip newPositions' wallPositions
legalMoves = filter (notBlocked maze) zipped
in tryMoves maze pos legalMoves | 375 | false | false | 0 | 11 | 91 | 156 | 84 | 72 | null | null |
ezyang/ghc | compiler/utils/Bag.hs | bsd-3-clause | anyBag :: (a -> Bool) -> Bag a -> Bool
anyBag _ EmptyBag = False | 71 | anyBag :: (a -> Bool) -> Bag a -> Bool
anyBag _ EmptyBag = False | 71 | anyBag _ EmptyBag = False | 32 | false | true | 0 | 7 | 21 | 34 | 17 | 17 | null | null |
bitemyapp/hdph-rs | src/Control/Parallel/HdpH/Strategies.hs | bsd-3-clause | -- | @parClosureListClusterBy cluster uncluster@ is a generic parallel
-- clustering strategy combinator for lists of Closures, evaluating
-- clusters generated by @cluster@ in parallel.
-- Clusters are distributed by lazy work stealing.
-- The function @uncluster@ must be a /left inverse/ of @cluster@,
-- that is @uncluster . cluster@ must be the identity.
parClosureListClusterBy :: ([Closure a] -> [[Closure a]])
-> ([[Closure a]] -> [Closure a])
-> Closure (Strategy (Closure a))
-> Strategy [Closure a]
parClosureListClusterBy cluster uncluster clo_strat =
evalClusterBy cluster' uncluster' strat'
where cluster' = map toClosure . cluster
uncluster' = uncluster . map unClosure
-- strat' :: Strategy [Closure [Closure a]]
strat' = parClosureList clo_strat''
-- clo_strat'' :: Closure (Strategy (Closure [Closure a]))
clo_strat'' =
$(mkClosure [| evalClosureListClosure |]) `apC` clo_strat | 1,031 | parClosureListClusterBy :: ([Closure a] -> [[Closure a]])
-> ([[Closure a]] -> [Closure a])
-> Closure (Strategy (Closure a))
-> Strategy [Closure a]
parClosureListClusterBy cluster uncluster clo_strat =
evalClusterBy cluster' uncluster' strat'
where cluster' = map toClosure . cluster
uncluster' = uncluster . map unClosure
-- strat' :: Strategy [Closure [Closure a]]
strat' = parClosureList clo_strat''
-- clo_strat'' :: Closure (Strategy (Closure [Closure a]))
clo_strat'' =
$(mkClosure [| evalClosureListClosure |]) `apC` clo_strat | 671 | parClosureListClusterBy cluster uncluster clo_strat =
evalClusterBy cluster' uncluster' strat'
where cluster' = map toClosure . cluster
uncluster' = uncluster . map unClosure
-- strat' :: Strategy [Closure [Closure a]]
strat' = parClosureList clo_strat''
-- clo_strat'' :: Closure (Strategy (Closure [Closure a]))
clo_strat'' =
$(mkClosure [| evalClosureListClosure |]) `apC` clo_strat | 449 | true | true | 4 | 12 | 260 | 172 | 92 | 80 | null | null |
y-kamiya/parallel-concurrent-haskell | src/Server/Kvs3/KvsMaster.hs | gpl-2.0 | createDB :: [NodeId] -> Process Database
createDB peers = spawnLocal $ do
pids <- forM peers $ \nid -> do
say $ "spawn on: " ++ show nid
spawn nid $ $(mkStaticClosure 'worker)
_ <- mapM_ monitor pids
let handle = forever $ do
receiveWait
[ match handleNotification
, match $ handleRequest pids
, matchAny $ \msg -> do
say $ printf "received unknownMessage: %s" (show msg)
]
if null pids
then worker
else handle | 500 | createDB :: [NodeId] -> Process Database
createDB peers = spawnLocal $ do
pids <- forM peers $ \nid -> do
say $ "spawn on: " ++ show nid
spawn nid $ $(mkStaticClosure 'worker)
_ <- mapM_ monitor pids
let handle = forever $ do
receiveWait
[ match handleNotification
, match $ handleRequest pids
, matchAny $ \msg -> do
say $ printf "received unknownMessage: %s" (show msg)
]
if null pids
then worker
else handle | 500 | createDB peers = spawnLocal $ do
pids <- forM peers $ \nid -> do
say $ "spawn on: " ++ show nid
spawn nid $ $(mkStaticClosure 'worker)
_ <- mapM_ monitor pids
let handle = forever $ do
receiveWait
[ match handleNotification
, match $ handleRequest pids
, matchAny $ \msg -> do
say $ printf "received unknownMessage: %s" (show msg)
]
if null pids
then worker
else handle | 459 | false | true | 0 | 28 | 164 | 171 | 80 | 91 | null | null |
Hara-Laboratory/subleq-mips | TestRFix2.hs | gpl-3.0 | prop_Lbi = testLSbi 3 lvui "lbuiTest" | 38 | prop_Lbi = testLSbi 3 lvui "lbuiTest" | 38 | prop_Lbi = testLSbi 3 lvui "lbuiTest" | 38 | false | false | 0 | 5 | 6 | 13 | 6 | 7 | null | null |
shlevy/ghc | compiler/prelude/PrelNames.hs | bsd-3-clause | gHC_IO_Exception = mkBaseModule (fsLit "GHC.IO.Exception") | 58 | gHC_IO_Exception = mkBaseModule (fsLit "GHC.IO.Exception") | 58 | gHC_IO_Exception = mkBaseModule (fsLit "GHC.IO.Exception") | 58 | false | false | 0 | 7 | 4 | 15 | 7 | 8 | null | null |
MichielDerhaeg/stack | src/Stack/Package.hs | bsd-3-clause | resolveFiles
:: (MonadIO m, MonadLogger m, MonadThrow m, MonadReader Ctx m)
=> [Path Abs Dir] -- ^ Directories to look in.
-> [DotCabalDescriptor] -- ^ Base names.
-> [Text] -- ^ Extensions.
-> m [(DotCabalDescriptor, Maybe DotCabalPath)]
resolveFiles dirs names exts =
forM names (\name -> liftM (name, ) (findCandidate dirs exts name)) | 361 | resolveFiles
:: (MonadIO m, MonadLogger m, MonadThrow m, MonadReader Ctx m)
=> [Path Abs Dir] -- ^ Directories to look in.
-> [DotCabalDescriptor] -- ^ Base names.
-> [Text] -- ^ Extensions.
-> m [(DotCabalDescriptor, Maybe DotCabalPath)]
resolveFiles dirs names exts =
forM names (\name -> liftM (name, ) (findCandidate dirs exts name)) | 361 | resolveFiles dirs names exts =
forM names (\name -> liftM (name, ) (findCandidate dirs exts name)) | 102 | false | true | 0 | 12 | 76 | 123 | 66 | 57 | null | null |
dysinger/amazonka | amazonka-rds/gen/Network/AWS/RDS/Types.hs | mpl-2.0 | -- | 'PendingModifiedValues' constructor.
--
-- The fields accessible through corresponding lenses are:
--
-- * 'pmvAllocatedStorage' @::@ 'Maybe' 'Int'
--
-- * 'pmvBackupRetentionPeriod' @::@ 'Maybe' 'Int'
--
-- * 'pmvDBInstanceClass' @::@ 'Maybe' 'Text'
--
-- * 'pmvDBInstanceIdentifier' @::@ 'Maybe' 'Text'
--
-- * 'pmvEngineVersion' @::@ 'Maybe' 'Text'
--
-- * 'pmvIops' @::@ 'Maybe' 'Int'
--
-- * 'pmvMasterUserPassword' @::@ 'Maybe' 'Text'
--
-- * 'pmvMultiAZ' @::@ 'Maybe' 'Bool'
--
-- * 'pmvPort' @::@ 'Maybe' 'Int'
--
-- * 'pmvStorageType' @::@ 'Maybe' 'Text'
--
pendingModifiedValues :: PendingModifiedValues
pendingModifiedValues = PendingModifiedValues
{ _pmvDBInstanceClass = Nothing
, _pmvAllocatedStorage = Nothing
, _pmvMasterUserPassword = Nothing
, _pmvPort = Nothing
, _pmvBackupRetentionPeriod = Nothing
, _pmvMultiAZ = Nothing
, _pmvEngineVersion = Nothing
, _pmvIops = Nothing
, _pmvDBInstanceIdentifier = Nothing
, _pmvStorageType = Nothing
} | 1,090 | pendingModifiedValues :: PendingModifiedValues
pendingModifiedValues = PendingModifiedValues
{ _pmvDBInstanceClass = Nothing
, _pmvAllocatedStorage = Nothing
, _pmvMasterUserPassword = Nothing
, _pmvPort = Nothing
, _pmvBackupRetentionPeriod = Nothing
, _pmvMultiAZ = Nothing
, _pmvEngineVersion = Nothing
, _pmvIops = Nothing
, _pmvDBInstanceIdentifier = Nothing
, _pmvStorageType = Nothing
} | 518 | pendingModifiedValues = PendingModifiedValues
{ _pmvDBInstanceClass = Nothing
, _pmvAllocatedStorage = Nothing
, _pmvMasterUserPassword = Nothing
, _pmvPort = Nothing
, _pmvBackupRetentionPeriod = Nothing
, _pmvMultiAZ = Nothing
, _pmvEngineVersion = Nothing
, _pmvIops = Nothing
, _pmvDBInstanceIdentifier = Nothing
, _pmvStorageType = Nothing
} | 471 | true | true | 0 | 7 | 255 | 101 | 72 | 29 | null | null |
jbracker/presentation-gen | src/PresentationGen/Types.hs | gpl-2.0 | getAuthors :: SlideM [(String, [Int])]
getAuthors = do
meta <- getSlideMetaData
return $ map (\(auth,a) -> (auth, map (read . trim) $ separateBy a ','))
$ combineAuthorAssocs
$ filter (fieldFilter ["Author", "Associated"]) meta
where
combineAuthorAssocs :: MetaData -> MetaData
combineAuthorAssocs (("Author", auth) : ("Associated", assoc) : xs) =
(auth, assoc) : combineAuthorAssocs xs
combineAuthorAssocs (("Author", auth) : xs) =
(auth, "") : combineAuthorAssocs xs
combineAuthorAssocs (x : xs) = combineAuthorAssocs xs
combineAuthorAssocs [] = [] | 606 | getAuthors :: SlideM [(String, [Int])]
getAuthors = do
meta <- getSlideMetaData
return $ map (\(auth,a) -> (auth, map (read . trim) $ separateBy a ','))
$ combineAuthorAssocs
$ filter (fieldFilter ["Author", "Associated"]) meta
where
combineAuthorAssocs :: MetaData -> MetaData
combineAuthorAssocs (("Author", auth) : ("Associated", assoc) : xs) =
(auth, assoc) : combineAuthorAssocs xs
combineAuthorAssocs (("Author", auth) : xs) =
(auth, "") : combineAuthorAssocs xs
combineAuthorAssocs (x : xs) = combineAuthorAssocs xs
combineAuthorAssocs [] = [] | 606 | getAuthors = do
meta <- getSlideMetaData
return $ map (\(auth,a) -> (auth, map (read . trim) $ separateBy a ','))
$ combineAuthorAssocs
$ filter (fieldFilter ["Author", "Associated"]) meta
where
combineAuthorAssocs :: MetaData -> MetaData
combineAuthorAssocs (("Author", auth) : ("Associated", assoc) : xs) =
(auth, assoc) : combineAuthorAssocs xs
combineAuthorAssocs (("Author", auth) : xs) =
(auth, "") : combineAuthorAssocs xs
combineAuthorAssocs (x : xs) = combineAuthorAssocs xs
combineAuthorAssocs [] = [] | 567 | false | true | 7 | 17 | 130 | 246 | 123 | 123 | null | null |
soumith/fbthrift | thrift/lib/hs/Thrift/Protocol/Binary.hs | apache-2.0 | parseBinaryMap :: ThriftType -> ThriftType -> Int32 -> P.Parser [(ThriftVal, ThriftVal)]
parseBinaryMap kt vt n | n <= 0 = return []
| otherwise = do
k <- parseBinaryValue kt
v <- parseBinaryValue vt
((k,v) :) <$> parseBinaryMap kt vt (n-1) | 269 | parseBinaryMap :: ThriftType -> ThriftType -> Int32 -> P.Parser [(ThriftVal, ThriftVal)]
parseBinaryMap kt vt n | n <= 0 = return []
| otherwise = do
k <- parseBinaryValue kt
v <- parseBinaryValue vt
((k,v) :) <$> parseBinaryMap kt vt (n-1) | 269 | parseBinaryMap kt vt n | n <= 0 = return []
| otherwise = do
k <- parseBinaryValue kt
v <- parseBinaryValue vt
((k,v) :) <$> parseBinaryMap kt vt (n-1) | 180 | false | true | 0 | 11 | 69 | 119 | 58 | 61 | null | null |
polachok/hs-nginx | src/Nginx/Utils.hs | mit | numAndSizeDirective :: Text -> Parser (Integer, Size)
numAndSizeDirective name = (,) <$> (string name *> skipSpace *> decimal) <*> (skipSpace *> size <* skipSpace <* char ';') | 175 | numAndSizeDirective :: Text -> Parser (Integer, Size)
numAndSizeDirective name = (,) <$> (string name *> skipSpace *> decimal) <*> (skipSpace *> size <* skipSpace <* char ';') | 175 | numAndSizeDirective name = (,) <$> (string name *> skipSpace *> decimal) <*> (skipSpace *> size <* skipSpace <* char ';') | 121 | false | true | 0 | 10 | 26 | 70 | 36 | 34 | null | null |
SimSaladin/hajong | hajong-server/src/Mahjong/Hand/Yaku/Builder.hs | mit | findMatch mp (x:xs)
| matchProp mp x = Just (x, xs)
| otherwise = findMatch mp xs & _Just._2 %~ (x:) | 113 | findMatch mp (x:xs)
| matchProp mp x = Just (x, xs)
| otherwise = findMatch mp xs & _Just._2 %~ (x:) | 113 | findMatch mp (x:xs)
| matchProp mp x = Just (x, xs)
| otherwise = findMatch mp xs & _Just._2 %~ (x:) | 113 | false | false | 0 | 8 | 33 | 66 | 32 | 34 | null | null |
sixears/fluffy | src/Fluffy/Data/List.hs | mit | -- | generate a list of differences between xs & ys
diff :: Eq a => [a] -> [a] -> [Diff a]
diff xs ys =
collapse Nothing $ DAD.getDiff xs ys
where
-- take a list of DAD.Diffs, convert to Diffs, spotting patterns of
-- n -x- First followed by n -x- Second; collapsing those into n -x- Change
collapse :: Eq a => Maybe (Either [a] [a]) -> [DAD.Diff a] -> [Diff a]
collapse_ (Just (Left firsts)) = fmap First firsts
collapse_ (Just (Right seconds)) = fmap Second seconds
collapse_ Nothing = []
collapse__ (DAD.First a : ds) = collapse (Just $ Left [a]) ds
collapse__ (DAD.Second a : ds) = collapse (Just $ Right [a]) ds
collapse__ (DAD.Both a b : ds) = Both a b : collapse Nothing ds
collapse__ [] = error "collapse__: empty list"
collapse pending [] = collapse_ pending
collapse Nothing ds = collapse__ ds
collapse (Just (Left [])) ds = collapse__ ds
collapse (Just (Right [])) ds = collapse__ ds
collapse (Just (Left firsts)) (DAD.First a : ds) =
collapse (Just $ Left (firsts ++ [a])) ds
collapse (Just (Right seconds)) (DAD.Second a : ds) =
collapse (Just $ Right (seconds ++ [a])) ds
collapse pending (DAD.Both a b : ds) =
collapse_ pending ++ [Both a b] ++ collapse Nothing ds
collapse (Just (Left (f:fs))) (DAD.Second a : ds) =
Change f a : collapse (Just $ Left fs) ds
collapse (Just (Right (s:ss))) (DAD.First a : ds) =
Change a s : collapse (Just $ Right ss) ds
-- subsequencePositions --------------------------------------------------------
-- | find the indices of (non-overlapping) instances of a sequence xs in ys;
-- e.g., @"abab" `subsequencePositions` "fabababab" ==> [1,5]@ | 1,791 | diff :: Eq a => [a] -> [a] -> [Diff a]
diff xs ys =
collapse Nothing $ DAD.getDiff xs ys
where
-- take a list of DAD.Diffs, convert to Diffs, spotting patterns of
-- n -x- First followed by n -x- Second; collapsing those into n -x- Change
collapse :: Eq a => Maybe (Either [a] [a]) -> [DAD.Diff a] -> [Diff a]
collapse_ (Just (Left firsts)) = fmap First firsts
collapse_ (Just (Right seconds)) = fmap Second seconds
collapse_ Nothing = []
collapse__ (DAD.First a : ds) = collapse (Just $ Left [a]) ds
collapse__ (DAD.Second a : ds) = collapse (Just $ Right [a]) ds
collapse__ (DAD.Both a b : ds) = Both a b : collapse Nothing ds
collapse__ [] = error "collapse__: empty list"
collapse pending [] = collapse_ pending
collapse Nothing ds = collapse__ ds
collapse (Just (Left [])) ds = collapse__ ds
collapse (Just (Right [])) ds = collapse__ ds
collapse (Just (Left firsts)) (DAD.First a : ds) =
collapse (Just $ Left (firsts ++ [a])) ds
collapse (Just (Right seconds)) (DAD.Second a : ds) =
collapse (Just $ Right (seconds ++ [a])) ds
collapse pending (DAD.Both a b : ds) =
collapse_ pending ++ [Both a b] ++ collapse Nothing ds
collapse (Just (Left (f:fs))) (DAD.Second a : ds) =
Change f a : collapse (Just $ Left fs) ds
collapse (Just (Right (s:ss))) (DAD.First a : ds) =
Change a s : collapse (Just $ Right ss) ds
-- subsequencePositions --------------------------------------------------------
-- | find the indices of (non-overlapping) instances of a sequence xs in ys;
-- e.g., @"abab" `subsequencePositions` "fabababab" ==> [1,5]@ | 1,738 | diff xs ys =
collapse Nothing $ DAD.getDiff xs ys
where
-- take a list of DAD.Diffs, convert to Diffs, spotting patterns of
-- n -x- First followed by n -x- Second; collapsing those into n -x- Change
collapse :: Eq a => Maybe (Either [a] [a]) -> [DAD.Diff a] -> [Diff a]
collapse_ (Just (Left firsts)) = fmap First firsts
collapse_ (Just (Right seconds)) = fmap Second seconds
collapse_ Nothing = []
collapse__ (DAD.First a : ds) = collapse (Just $ Left [a]) ds
collapse__ (DAD.Second a : ds) = collapse (Just $ Right [a]) ds
collapse__ (DAD.Both a b : ds) = Both a b : collapse Nothing ds
collapse__ [] = error "collapse__: empty list"
collapse pending [] = collapse_ pending
collapse Nothing ds = collapse__ ds
collapse (Just (Left [])) ds = collapse__ ds
collapse (Just (Right [])) ds = collapse__ ds
collapse (Just (Left firsts)) (DAD.First a : ds) =
collapse (Just $ Left (firsts ++ [a])) ds
collapse (Just (Right seconds)) (DAD.Second a : ds) =
collapse (Just $ Right (seconds ++ [a])) ds
collapse pending (DAD.Both a b : ds) =
collapse_ pending ++ [Both a b] ++ collapse Nothing ds
collapse (Just (Left (f:fs))) (DAD.Second a : ds) =
Change f a : collapse (Just $ Left fs) ds
collapse (Just (Right (s:ss))) (DAD.First a : ds) =
Change a s : collapse (Just $ Right ss) ds
-- subsequencePositions --------------------------------------------------------
-- | find the indices of (non-overlapping) instances of a sequence xs in ys;
-- e.g., @"abab" `subsequencePositions` "fabababab" ==> [1,5]@ | 1,699 | true | true | 19 | 16 | 483 | 664 | 337 | 327 | null | null |
danr/hipspec | testsuite/prod/zeno_version/PropT42.hs | gpl-3.0 | drop (S x) (_:xs) = drop x xs | 29 | drop (S x) (_:xs) = drop x xs | 29 | drop (S x) (_:xs) = drop x xs | 29 | false | false | 1 | 7 | 7 | 31 | 14 | 17 | null | null |
haasn/colour | Data/Colour/Names.hs | mit | goldenrod :: (Ord a, Floating a) => Colour a
goldenrod = sRGB24 218 165 32 | 74 | goldenrod :: (Ord a, Floating a) => Colour a
goldenrod = sRGB24 218 165 32 | 74 | goldenrod = sRGB24 218 165 32 | 29 | false | true | 0 | 7 | 14 | 44 | 19 | 25 | null | null |
kazu-yamamoto/dns | internal/Network/DNS/StateBinary.hs | bsd-3-clause | -- plain punctuation
-- | Some numeric byte constants.
zero, semi, atsign, bslash :: Word8
zero = fromIntegral $ fromEnum '0' | 126 | zero, semi, atsign, bslash :: Word8
zero = fromIntegral $ fromEnum '0' | 70 | zero = fromIntegral $ fromEnum '0' | 34 | true | true | 2 | 6 | 21 | 30 | 17 | 13 | null | null |
seereason/HJScript | src/HJScript/DOM/ElementNode.hs | bsd-3-clause | parentNode :: IsElementNode n => Exp n -> Exp Node
parentNode = deref "parentNode" | 82 | parentNode :: IsElementNode n => Exp n -> Exp Node
parentNode = deref "parentNode" | 82 | parentNode = deref "parentNode" | 31 | false | true | 0 | 7 | 13 | 31 | 14 | 17 | null | null |
Softsapiens/yampy-cube | src/Graphics.hs | bsd-3-clause | translate :: (Num a, Eq a) => (a, a) -> [(a, a)] -> [(a, a)]
translate v = map (v .+) | 85 | translate :: (Num a, Eq a) => (a, a) -> [(a, a)] -> [(a, a)]
translate v = map (v .+) | 85 | translate v = map (v .+) | 24 | false | true | 0 | 9 | 20 | 68 | 39 | 29 | null | null |
neglectedvalue/xmobar-freebsd | Plugins/Monitors/Common.hs | bsd-3-clause | skipTillString :: String -> Parser String
skipTillString s =
manyTill skipRestOfLine $ string s | 100 | skipTillString :: String -> Parser String
skipTillString s =
manyTill skipRestOfLine $ string s | 100 | skipTillString s =
manyTill skipRestOfLine $ string s | 58 | false | true | 0 | 6 | 18 | 31 | 14 | 17 | null | null |
bitemyapp/hpp | src/Hpp/Expr.hs | bsd-3-clause | readNarrowChar :: String -> Maybe Char
readNarrowChar ['\'',c,'\''] = Just c | 76 | readNarrowChar :: String -> Maybe Char
readNarrowChar ['\'',c,'\''] = Just c | 76 | readNarrowChar ['\'',c,'\''] = Just c | 37 | false | true | 0 | 6 | 10 | 27 | 13 | 14 | null | null |
brendanhay/gogol | gogol-logging/gen/Network/Google/Resource/Logging/Projects/Locations/Buckets/Views/Create.hs | mpl-2.0 | -- | Multipart request metadata.
plbvcPayload :: Lens' ProjectsLocationsBucketsViewsCreate LogView
plbvcPayload
= lens _plbvcPayload (\ s a -> s{_plbvcPayload = a}) | 166 | plbvcPayload :: Lens' ProjectsLocationsBucketsViewsCreate LogView
plbvcPayload
= lens _plbvcPayload (\ s a -> s{_plbvcPayload = a}) | 133 | plbvcPayload
= lens _plbvcPayload (\ s a -> s{_plbvcPayload = a}) | 67 | true | true | 0 | 9 | 22 | 42 | 22 | 20 | null | null |
tobytripp/SpiraJira | src/Main.hs | lgpl-3.0 | transitionsUrl :: String -> TicketId -> String
transitionsUrl baseUrl key = (issueUrl baseUrl key) ++ "/transitions" | 116 | transitionsUrl :: String -> TicketId -> String
transitionsUrl baseUrl key = (issueUrl baseUrl key) ++ "/transitions" | 116 | transitionsUrl baseUrl key = (issueUrl baseUrl key) ++ "/transitions" | 69 | false | true | 0 | 7 | 15 | 36 | 18 | 18 | null | null |
kowey/GenI | geni-gui/src/NLP/GenI/Simple/SimpleGui.hs | gpl-2.0 | simpleGui1p = simpleGui False | 29 | simpleGui1p = simpleGui False | 29 | simpleGui1p = simpleGui False | 29 | false | false | 0 | 5 | 3 | 9 | 4 | 5 | null | null |
ambiata/mafia | src/Mafia/Cabal/Sandbox.hs | bsd-3-clause | initSandbox :: EitherT CabalError IO SandboxDir
initSandbox = do
sandboxDir <- getInferredSandboxDir
cfgSandboxDir <- liftIO (runEitherT getSandboxDir)
let cfgOk = dropLeft cfgSandboxDir == Just sandboxDir
dirOk <- doesDirectoryExist sandboxDir
unless (cfgOk && dirOk) $ do
PassErr <- call CabalProcessError "cabal" ["sandbox", "--sandbox", sandboxDir, "init"]
return ()
return sandboxDir | 411 | initSandbox :: EitherT CabalError IO SandboxDir
initSandbox = do
sandboxDir <- getInferredSandboxDir
cfgSandboxDir <- liftIO (runEitherT getSandboxDir)
let cfgOk = dropLeft cfgSandboxDir == Just sandboxDir
dirOk <- doesDirectoryExist sandboxDir
unless (cfgOk && dirOk) $ do
PassErr <- call CabalProcessError "cabal" ["sandbox", "--sandbox", sandboxDir, "init"]
return ()
return sandboxDir | 411 | initSandbox = do
sandboxDir <- getInferredSandboxDir
cfgSandboxDir <- liftIO (runEitherT getSandboxDir)
let cfgOk = dropLeft cfgSandboxDir == Just sandboxDir
dirOk <- doesDirectoryExist sandboxDir
unless (cfgOk && dirOk) $ do
PassErr <- call CabalProcessError "cabal" ["sandbox", "--sandbox", sandboxDir, "init"]
return ()
return sandboxDir | 363 | false | true | 0 | 12 | 70 | 127 | 58 | 69 | null | null |
gergoerdi/tinymicro-mos6502-kansas-lava | lava/TinyMicro/Machine.hs | gpl-2.0 | synthesize :: BS.ByteString -> IO [(String, String)]
synthesize prog = do
boardKLEG <- reifyFabric $ do
theClk cpuClock
wing_init
let vpipe = Board.board prog
(we, w) = unpackEnabled vpipe
(wAddr, wData) = unpack w
outStdLogic "VIDEO_WE" we
outStdLogicVector "VIDEO_W_ADDR" wAddr
outStdLogicVector "VIDEO_W_DATA" wData
boardMod <- netlistCircuit "MainBoard" boardKLEG
let boardVHDL = genVHDL boardMod ["work.lava.all", "work.all"]
videoKLEG <- reifyFabric $ do
theClk vidClock
wing_init
rData <- inStdLogicVector "VIDEO_R_DATA"
let (rAddr, VGADriverOut{..}) = Video.vgaFB Video.palette rData
outStdLogicVector "VIDEO_R_ADDR" $ enabledVal rAddr
vga $ encodeVGA vgaOut
videoMod <- netlistCircuit "Video" videoKLEG
let videoVHDL = genVHDL videoMod ["work.lava.all", "work.all"]
return [("MainBoard", boardVHDL), ("Video", videoVHDL)]
where
cpuClock = "CLK_CPU"
vidClock = "CLK_40MHZ" | 1,041 | synthesize :: BS.ByteString -> IO [(String, String)]
synthesize prog = do
boardKLEG <- reifyFabric $ do
theClk cpuClock
wing_init
let vpipe = Board.board prog
(we, w) = unpackEnabled vpipe
(wAddr, wData) = unpack w
outStdLogic "VIDEO_WE" we
outStdLogicVector "VIDEO_W_ADDR" wAddr
outStdLogicVector "VIDEO_W_DATA" wData
boardMod <- netlistCircuit "MainBoard" boardKLEG
let boardVHDL = genVHDL boardMod ["work.lava.all", "work.all"]
videoKLEG <- reifyFabric $ do
theClk vidClock
wing_init
rData <- inStdLogicVector "VIDEO_R_DATA"
let (rAddr, VGADriverOut{..}) = Video.vgaFB Video.palette rData
outStdLogicVector "VIDEO_R_ADDR" $ enabledVal rAddr
vga $ encodeVGA vgaOut
videoMod <- netlistCircuit "Video" videoKLEG
let videoVHDL = genVHDL videoMod ["work.lava.all", "work.all"]
return [("MainBoard", boardVHDL), ("Video", videoVHDL)]
where
cpuClock = "CLK_CPU"
vidClock = "CLK_40MHZ" | 1,041 | synthesize prog = do
boardKLEG <- reifyFabric $ do
theClk cpuClock
wing_init
let vpipe = Board.board prog
(we, w) = unpackEnabled vpipe
(wAddr, wData) = unpack w
outStdLogic "VIDEO_WE" we
outStdLogicVector "VIDEO_W_ADDR" wAddr
outStdLogicVector "VIDEO_W_DATA" wData
boardMod <- netlistCircuit "MainBoard" boardKLEG
let boardVHDL = genVHDL boardMod ["work.lava.all", "work.all"]
videoKLEG <- reifyFabric $ do
theClk vidClock
wing_init
rData <- inStdLogicVector "VIDEO_R_DATA"
let (rAddr, VGADriverOut{..}) = Video.vgaFB Video.palette rData
outStdLogicVector "VIDEO_R_ADDR" $ enabledVal rAddr
vga $ encodeVGA vgaOut
videoMod <- netlistCircuit "Video" videoKLEG
let videoVHDL = genVHDL videoMod ["work.lava.all", "work.all"]
return [("MainBoard", boardVHDL), ("Video", videoVHDL)]
where
cpuClock = "CLK_CPU"
vidClock = "CLK_40MHZ" | 988 | false | true | 0 | 16 | 267 | 305 | 143 | 162 | null | null |
phaazon/OpenGLRaw | src/Graphics/Rendering/OpenGL/Raw/Tokens.hs | bsd-3-clause | gl_PATH_MAX_PROJECTION_STACK_DEPTH_NV :: GLenum
gl_PATH_MAX_PROJECTION_STACK_DEPTH_NV = 0x0D38 | 94 | gl_PATH_MAX_PROJECTION_STACK_DEPTH_NV :: GLenum
gl_PATH_MAX_PROJECTION_STACK_DEPTH_NV = 0x0D38 | 94 | gl_PATH_MAX_PROJECTION_STACK_DEPTH_NV = 0x0D38 | 46 | false | true | 0 | 4 | 5 | 11 | 6 | 5 | null | null |
elaye/svg-parser | src/Elements.hs | bsd-3-clause | -- | Any element.
anyTag :: Parsec String () ElementName
anyTag = do
name <- Parsec.many1 $ Parsec.noneOf " =\n\r"
return $ ElementName name | 144 | anyTag :: Parsec String () ElementName
anyTag = do
name <- Parsec.many1 $ Parsec.noneOf " =\n\r"
return $ ElementName name | 126 | anyTag = do
name <- Parsec.many1 $ Parsec.noneOf " =\n\r"
return $ ElementName name | 87 | true | true | 0 | 10 | 27 | 49 | 23 | 26 | null | null |
ulyssesp/oscillare | src/Visuals.hs | gpl-3.0 | buddhist = Palette $ Hex . BS.pack . fmap toUpper <$> ["0000FF", "FFFF00", "FF0000", "FFFFFF", "FF9800"] | 104 | buddhist = Palette $ Hex . BS.pack . fmap toUpper <$> ["0000FF", "FFFF00", "FF0000", "FFFFFF", "FF9800"] | 104 | buddhist = Palette $ Hex . BS.pack . fmap toUpper <$> ["0000FF", "FFFF00", "FF0000", "FFFFFF", "FF9800"] | 104 | false | false | 0 | 8 | 15 | 42 | 23 | 19 | null | null |
luqui/collada | Graphics/Formats/Collada.hs | bsd-3-clause | -- | Takes a prefix and returns a texture loader that prepends the prefix to the path
-- and loads from disk.
pathTextureLoader :: String -> String -> IO GL.TextureObject
pathTextureLoader prefix path = do
let loc = prefix ++ "/" ++ path
e <- Image.loadImage loc
case e of
Left err -> fail $ "Couldn't load " ++ loc ++ ": " ++ err
Right bmp -> Bitmap.makeSimpleBitmapTexture bmp | 406 | pathTextureLoader :: String -> String -> IO GL.TextureObject
pathTextureLoader prefix path = do
let loc = prefix ++ "/" ++ path
e <- Image.loadImage loc
case e of
Left err -> fail $ "Couldn't load " ++ loc ++ ": " ++ err
Right bmp -> Bitmap.makeSimpleBitmapTexture bmp | 296 | pathTextureLoader prefix path = do
let loc = prefix ++ "/" ++ path
e <- Image.loadImage loc
case e of
Left err -> fail $ "Couldn't load " ++ loc ++ ": " ++ err
Right bmp -> Bitmap.makeSimpleBitmapTexture bmp | 235 | true | true | 0 | 14 | 97 | 111 | 51 | 60 | null | null |
forsyde/forsyde-shallow | src/ForSyDe/Shallow/Utility/Memory.hs | bsd-3-clause | writeMem :: Memory a -> (Int, a) -> Memory a
writeMem (Mem size vs) (i, x)
| i < size && i >= 0 = Mem size (replaceV vs i (abstExt x))
| otherwise = Mem size vs | 178 | writeMem :: Memory a -> (Int, a) -> Memory a
writeMem (Mem size vs) (i, x)
| i < size && i >= 0 = Mem size (replaceV vs i (abstExt x))
| otherwise = Mem size vs | 178 | writeMem (Mem size vs) (i, x)
| i < size && i >= 0 = Mem size (replaceV vs i (abstExt x))
| otherwise = Mem size vs | 133 | false | true | 1 | 10 | 55 | 101 | 50 | 51 | null | null |
DavidAlphaFox/ghc | libraries/containers/Data/IntMap/Base.hs | bsd-3-clause | foldlFB :: (a -> Key -> b -> a) -> a -> IntMap b -> a
foldlFB = foldlWithKey | 76 | foldlFB :: (a -> Key -> b -> a) -> a -> IntMap b -> a
foldlFB = foldlWithKey | 76 | foldlFB = foldlWithKey | 22 | false | true | 0 | 9 | 18 | 41 | 21 | 20 | null | null |
termite2/simple-abstractor | SimpleAbstractor/Parser.hs | bsd-3-clause | tp t@T.TokenParser{..} = (Right <$> typ t) <|> (Left <$> identifier) | 75 | tp t@T.TokenParser{..} = (Right <$> typ t) <|> (Left <$> identifier) | 75 | tp t@T.TokenParser{..} = (Right <$> typ t) <|> (Left <$> identifier) | 75 | false | false | 1 | 8 | 17 | 50 | 22 | 28 | null | null |
siddhanathan/ghc | compiler/typecheck/TcRnTypes.hs | bsd-3-clause | ctEvId ctev = pprPanic "ctEvId:" (ppr ctev) | 43 | ctEvId ctev = pprPanic "ctEvId:" (ppr ctev) | 43 | ctEvId ctev = pprPanic "ctEvId:" (ppr ctev) | 43 | false | false | 0 | 7 | 6 | 20 | 9 | 11 | null | null |
bacchanalia/KitchenSink | KitchenSink/Qualified.hs | gpl-3.0 | -- |'VM.read'
vm_read = VM.read | 31 | vm_read = VM.read | 17 | vm_read = VM.read | 17 | true | false | 0 | 5 | 4 | 9 | 5 | 4 | null | null |
simonmichael/hledger | hledger-lib/Hledger/Data/Posting.hs | gpl-3.0 | -- | Apply a specified valuation to this posting's amount, using the
-- provided price oracle, commodity styles, and reference dates.
-- See amountApplyValuation.
postingApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> ValuationType -> Posting -> Posting
postingApplyValuation priceoracle styles periodlast today v p =
postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p | 464 | postingApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> ValuationType -> Posting -> Posting
postingApplyValuation priceoracle styles periodlast today v p =
postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p | 301 | postingApplyValuation priceoracle styles periodlast today v p =
postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p | 174 | true | true | 0 | 10 | 62 | 85 | 43 | 42 | null | null |
rvion/lamdu | bottlelib/Graphics/UI/Bottle/View.hs | gpl-3.0 | width :: Lens' View R
width = size . _1 | 39 | width :: Lens' View R
width = size . _1 | 39 | width = size . _1 | 17 | false | true | 0 | 5 | 9 | 20 | 10 | 10 | null | null |
jtdaugherty/mathblog | src/MB/Server.hs | bsd-3-clause | fileToResponse :: FilePath -> IO (Response BS.ByteString)
fileToResponse f = do
bytes <- BS.readFile f
return $ (respond Found :: Response BS.ByteString)
{ rspHeaders = [ Header HdrContentLength $ show $ BS.length bytes
, Header HdrCacheControl "no-cache"
]
, rspBody = bytes
} | 376 | fileToResponse :: FilePath -> IO (Response BS.ByteString)
fileToResponse f = do
bytes <- BS.readFile f
return $ (respond Found :: Response BS.ByteString)
{ rspHeaders = [ Header HdrContentLength $ show $ BS.length bytes
, Header HdrCacheControl "no-cache"
]
, rspBody = bytes
} | 376 | fileToResponse f = do
bytes <- BS.readFile f
return $ (respond Found :: Response BS.ByteString)
{ rspHeaders = [ Header HdrContentLength $ show $ BS.length bytes
, Header HdrCacheControl "no-cache"
]
, rspBody = bytes
} | 318 | false | true | 0 | 13 | 141 | 103 | 51 | 52 | null | null |
input-output-hk/pos-haskell-prototype | chain/src/Pos/Chain/Txp/Toil/Monad.hs | mit | -- | Put a transaction with corresponding 'TxUndo' into MemPool.
-- Transaction must not be in MemPool (but it's checked anyway).
putTxWithUndo :: TxId -> TxAux -> TxUndo -> LocalToilM ()
putTxWithUndo id tx undo =
unlessM (hasTx id) $ do
ltsMemPool . mpLocalTxs . at id .= Just tx
ltsMemPool . mpSize += 1
ltsUndos . at id .= Just undo
-- | Return the number of transactions contained in the pool. | 427 | putTxWithUndo :: TxId -> TxAux -> TxUndo -> LocalToilM ()
putTxWithUndo id tx undo =
unlessM (hasTx id) $ do
ltsMemPool . mpLocalTxs . at id .= Just tx
ltsMemPool . mpSize += 1
ltsUndos . at id .= Just undo
-- | Return the number of transactions contained in the pool. | 297 | putTxWithUndo id tx undo =
unlessM (hasTx id) $ do
ltsMemPool . mpLocalTxs . at id .= Just tx
ltsMemPool . mpSize += 1
ltsUndos . at id .= Just undo
-- | Return the number of transactions contained in the pool. | 239 | true | true | 0 | 10 | 101 | 100 | 47 | 53 | null | null |
dan-t/layers | src/Ressources.hs | bsd-3-clause | getDataFileName :: FilePath -> IO FilePath
getDataFileName path =
#ifdef CABAL
PL.getDataFileName path | 105 | getDataFileName :: FilePath -> IO FilePath
getDataFileName path =
#ifdef CABAL
PL.getDataFileName path | 105 | getDataFileName path =
#ifdef CABAL
PL.getDataFileName path | 62 | false | true | 0 | 7 | 15 | 32 | 14 | 18 | null | null |
stothardj/Sequence-Generator | Main.hs | bsd-3-clause | promptPolynomial :: IO [Double]
promptPolynomial =
do
putStr "Polynomial sequence { c*(x0+i*d)^n } for i = 0,1,2, ..., L-1.\nEnter the degree n: "
n <- fmap read getLine :: IO Double
putStr "Enter the constant multiplier c: "
c <- fmap read getLine :: IO Double
putStr "Enter the initial value of the base x0: "
x0 <- fmap read getLine :: IO Double
putStr "Enter the base increment d: "
d <- fmap read getLine :: IO Double
putStr "Enter the fragment length L: "
l <- fmap read getLine
return [ c * (x0 + i * d) ** n | i <- [0..l-1]] | 638 | promptPolynomial :: IO [Double]
promptPolynomial =
do
putStr "Polynomial sequence { c*(x0+i*d)^n } for i = 0,1,2, ..., L-1.\nEnter the degree n: "
n <- fmap read getLine :: IO Double
putStr "Enter the constant multiplier c: "
c <- fmap read getLine :: IO Double
putStr "Enter the initial value of the base x0: "
x0 <- fmap read getLine :: IO Double
putStr "Enter the base increment d: "
d <- fmap read getLine :: IO Double
putStr "Enter the fragment length L: "
l <- fmap read getLine
return [ c * (x0 + i * d) ** n | i <- [0..l-1]] | 638 | promptPolynomial =
do
putStr "Polynomial sequence { c*(x0+i*d)^n } for i = 0,1,2, ..., L-1.\nEnter the degree n: "
n <- fmap read getLine :: IO Double
putStr "Enter the constant multiplier c: "
c <- fmap read getLine :: IO Double
putStr "Enter the initial value of the base x0: "
x0 <- fmap read getLine :: IO Double
putStr "Enter the base increment d: "
d <- fmap read getLine :: IO Double
putStr "Enter the fragment length L: "
l <- fmap read getLine
return [ c * (x0 + i * d) ** n | i <- [0..l-1]] | 606 | false | true | 0 | 13 | 211 | 176 | 79 | 97 | null | null |
seL4/capDL-tool | CapDL/State.hs | bsd-2-clause | slotCap :: CapRef -> Model Word -> Cap
slotCap cref = fromJust . maybeSlotCap cref | 82 | slotCap :: CapRef -> Model Word -> Cap
slotCap cref = fromJust . maybeSlotCap cref | 82 | slotCap cref = fromJust . maybeSlotCap cref | 43 | false | true | 1 | 8 | 14 | 39 | 16 | 23 | null | null |
spacekitteh/smcghc | compiler/cmm/PprC.hs | bsd-3-clause | pprExpr1 e@(CmmReg _reg) = pprExpr e | 37 | pprExpr1 e@(CmmReg _reg) = pprExpr e | 37 | pprExpr1 e@(CmmReg _reg) = pprExpr e | 37 | false | false | 0 | 8 | 6 | 21 | 10 | 11 | null | null |
bitemyapp/persistent | persistent/Database/Persist/Class/PersistUnique.hs | mit | -- TODO: expose this to users
recordName
:: (PersistEntity record)
=> record -> Text
recordName = unHaskellName . entityHaskell . entityDef . Just | 154 | recordName
:: (PersistEntity record)
=> record -> Text
recordName = unHaskellName . entityHaskell . entityDef . Just | 124 | recordName = unHaskellName . entityHaskell . entityDef . Just | 61 | true | true | 0 | 7 | 30 | 41 | 21 | 20 | null | null |
spechub/Hets | Propositional/Parse_AS_Basic.hs | gpl-2.0 | -- | Parser for equivalence @<=>@
equivKey :: AParser st Token
equivKey = asKey equivS | 86 | equivKey :: AParser st Token
equivKey = asKey equivS | 52 | equivKey = asKey equivS | 23 | true | true | 0 | 5 | 14 | 20 | 10 | 10 | null | null |
haskell-opengl/OpenGLRaw | src/Graphics/GL/Functions/F16.hs | bsd-3-clause | -- glMapVertexAttrib2dAPPLE ----------------------------------------------------
glMapVertexAttrib2dAPPLE
:: MonadIO m
=> GLuint -- ^ @index@.
-> GLuint -- ^ @size@.
-> GLdouble -- ^ @u1@ of type @CoordD@.
-> GLdouble -- ^ @u2@ of type @CoordD@.
-> GLint -- ^ @ustride@.
-> GLint -- ^ @uorder@ of type @CheckedInt32@.
-> GLdouble -- ^ @v1@ of type @CoordD@.
-> GLdouble -- ^ @v2@ of type @CoordD@.
-> GLint -- ^ @vstride@.
-> GLint -- ^ @vorder@ of type @CheckedInt32@.
-> Ptr GLdouble -- ^ @points@ pointing to @COMPSIZE(size,ustride,uorder,vstride,vorder)@ elements of type @CoordD@.
-> m ()
glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 = liftIO $ dyn540 ptr_glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 | 762 | glMapVertexAttrib2dAPPLE
:: MonadIO m
=> GLuint -- ^ @index@.
-> GLuint -- ^ @size@.
-> GLdouble -- ^ @u1@ of type @CoordD@.
-> GLdouble -- ^ @u2@ of type @CoordD@.
-> GLint -- ^ @ustride@.
-> GLint -- ^ @uorder@ of type @CheckedInt32@.
-> GLdouble -- ^ @v1@ of type @CoordD@.
-> GLdouble -- ^ @v2@ of type @CoordD@.
-> GLint -- ^ @vstride@.
-> GLint -- ^ @vorder@ of type @CheckedInt32@.
-> Ptr GLdouble -- ^ @points@ pointing to @COMPSIZE(size,ustride,uorder,vstride,vorder)@ elements of type @CoordD@.
-> m ()
glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 = liftIO $ dyn540 ptr_glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 | 680 | glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 = liftIO $ dyn540 ptr_glMapVertexAttrib2dAPPLE v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 | 141 | true | true | 0 | 19 | 145 | 138 | 72 | 66 | null | null |
DNNX/hyphenation | src/Text/Hyphenation/Language.hs | bsd-3-clause | greek_Poly = unsafePerformIO (loadHyphenator (languageAffix Greek_Poly)) | 72 | greek_Poly = unsafePerformIO (loadHyphenator (languageAffix Greek_Poly)) | 72 | greek_Poly = unsafePerformIO (loadHyphenator (languageAffix Greek_Poly)) | 72 | false | false | 0 | 9 | 5 | 21 | 10 | 11 | null | null |
omefire/lens | src/Data/Text/Lazy/Lens.hs | bsd-3-clause | -- | This is an alias for 'unpacked' that makes it clearer how to use it with @('#')@.
--
-- @
-- '_Text' = 'from' 'packed'
-- @
--
-- >>> _Text # "hello" -- :: Text
-- "hello"
_Text :: Iso' Text String
_Text = from packed | 222 | _Text :: Iso' Text String
_Text = from packed | 45 | _Text = from packed | 19 | true | true | 0 | 5 | 47 | 27 | 17 | 10 | null | null |
gtk2hs/soegtk | Graphics/SOE/Gtk.hs | lgpl-2.1 | emptyGraphic :: Graphic
emptyGraphic = Graphic (\_ -> return ()) | 64 | emptyGraphic :: Graphic
emptyGraphic = Graphic (\_ -> return ()) | 64 | emptyGraphic = Graphic (\_ -> return ()) | 40 | false | true | 0 | 9 | 9 | 27 | 14 | 13 | null | null |
fffej/HS-Poker | LookupNaive.hs | bsd-3-clause | lookupFlushes :: Int -> Int
lookupFlushes n = flushes V.! n | 59 | lookupFlushes :: Int -> Int
lookupFlushes n = flushes V.! n | 59 | lookupFlushes n = flushes V.! n | 31 | false | true | 0 | 5 | 10 | 24 | 12 | 12 | null | null |
Kiandr/CrackingCodingInterview | Haskell/src/chapter-3/Data/Queue.hs | mit | isEmpty (Queue _ _ ) = False | 29 | isEmpty (Queue _ _ ) = False | 29 | isEmpty (Queue _ _ ) = False | 29 | false | false | 0 | 6 | 7 | 18 | 8 | 10 | null | null |
mydaum/cabal | cabal-install/Distribution/Client/ProjectPlanning.hs | bsd-3-clause | programsMonitorFiles :: ProgramDb -> [MonitorFilePath]
programsMonitorFiles progdb =
[ monitor
| prog <- configuredPrograms progdb
, monitor <- monitorFileSearchPath (programMonitorFiles prog)
(programPath prog)
] | 271 | programsMonitorFiles :: ProgramDb -> [MonitorFilePath]
programsMonitorFiles progdb =
[ monitor
| prog <- configuredPrograms progdb
, monitor <- monitorFileSearchPath (programMonitorFiles prog)
(programPath prog)
] | 271 | programsMonitorFiles progdb =
[ monitor
| prog <- configuredPrograms progdb
, monitor <- monitorFileSearchPath (programMonitorFiles prog)
(programPath prog)
] | 216 | false | true | 0 | 10 | 81 | 60 | 30 | 30 | null | null |
sdiehl/ghc | testsuite/tests/plugins/simple-plugin/Simple/RemovePlugin.hs | bsd-3-clause | plugin :: Plugin
plugin = defaultPlugin { parsedResultAction = parsedPlugin
, typeCheckResultAction = typecheckPlugin
, spliceRunAction = metaPlugin'
, interfaceLoadAction = interfaceLoadPlugin'
} | 288 | plugin :: Plugin
plugin = defaultPlugin { parsedResultAction = parsedPlugin
, typeCheckResultAction = typecheckPlugin
, spliceRunAction = metaPlugin'
, interfaceLoadAction = interfaceLoadPlugin'
} | 288 | plugin = defaultPlugin { parsedResultAction = parsedPlugin
, typeCheckResultAction = typecheckPlugin
, spliceRunAction = metaPlugin'
, interfaceLoadAction = interfaceLoadPlugin'
} | 271 | false | true | 0 | 6 | 114 | 37 | 23 | 14 | null | null |
henrytill/deviser | src/Deviser/Evaluator.hs | bsd-3-clause | cdr x = throwError (NumArgs 1 x) | 58 | cdr x = throwError (NumArgs 1 x) | 58 | cdr x = throwError (NumArgs 1 x) | 58 | false | false | 0 | 7 | 32 | 20 | 9 | 11 | null | null |
glutamate/inliterate | InOut.hs | bsd-3-clause | maySrc (SpliceDecl sloc (InfixApp (Var (UnQual (Ident vnm)))
(QVarOp (UnQual (Symbol "<*"))) src)) = Just (sloc, vnm, src) | 123 | maySrc (SpliceDecl sloc (InfixApp (Var (UnQual (Ident vnm)))
(QVarOp (UnQual (Symbol "<*"))) src)) = Just (sloc, vnm, src) | 123 | maySrc (SpliceDecl sloc (InfixApp (Var (UnQual (Ident vnm)))
(QVarOp (UnQual (Symbol "<*"))) src)) = Just (sloc, vnm, src) | 123 | false | false | 0 | 15 | 18 | 75 | 38 | 37 | null | null |
uduki/hsQt | Qtc/Enums/Gui/QAbstractItemView.hs | bsd-2-clause | eAnyKeyPressed :: EditTrigger
eAnyKeyPressed
= ieEditTrigger $ 16 | 67 | eAnyKeyPressed :: EditTrigger
eAnyKeyPressed
= ieEditTrigger $ 16 | 67 | eAnyKeyPressed
= ieEditTrigger $ 16 | 37 | false | true | 0 | 6 | 9 | 18 | 8 | 10 | null | null |
qzchenwl/r-proxy | src/Utils.hs | bsd-3-clause | update :: (Eq k) => (k, v) -> [(k, v)] -> [(k, v)]
update (k, v) l = (k, v) : filter (\(k', _) -> k' /= k) l | 108 | update :: (Eq k) => (k, v) -> [(k, v)] -> [(k, v)]
update (k, v) l = (k, v) : filter (\(k', _) -> k' /= k) l | 108 | update (k, v) l = (k, v) : filter (\(k', _) -> k' /= k) l | 57 | false | true | 2 | 11 | 28 | 102 | 57 | 45 | null | null |
osa1/vindinium | src/Main.hs | mit | arenaCmd :: Parser Cmd
arenaCmd = Arena <$> settings | 52 | arenaCmd :: Parser Cmd
arenaCmd = Arena <$> settings | 52 | arenaCmd = Arena <$> settings | 29 | false | true | 1 | 6 | 8 | 22 | 9 | 13 | null | null |
bergey/diagrams-opengl | src/Graphics/Rendering/Util.hs | bsd-3-clause | p2ToV3 :: P2 -> L.V3 GLfloat
p2ToV3 (unp2 -> (x, y)) = L.V3 (r2f x) (r2f y) 0 | 77 | p2ToV3 :: P2 -> L.V3 GLfloat
p2ToV3 (unp2 -> (x, y)) = L.V3 (r2f x) (r2f y) 0 | 77 | p2ToV3 (unp2 -> (x, y)) = L.V3 (r2f x) (r2f y) 0 | 48 | false | true | 0 | 10 | 17 | 61 | 30 | 31 | null | null |
DimaSamoz/mezzo | src/Mezzo/Compose/Templates.hs | mit | durLitFormatter :: Formatter
durLitFormatter = ('_' :) . map toLower . take 2 . nameBase | 88 | durLitFormatter :: Formatter
durLitFormatter = ('_' :) . map toLower . take 2 . nameBase | 88 | durLitFormatter = ('_' :) . map toLower . take 2 . nameBase | 59 | false | true | 1 | 7 | 14 | 41 | 18 | 23 | null | null |
myuon/DOTO | src/Api/TodoItem.hs | mit | selectTodoItems :: IO [TodoItem]
selectTodoItems = do
todos <- runDB connInfo $ selectList [] []
return $ (\(Entity _ u) -> u) <$> todos | 140 | selectTodoItems :: IO [TodoItem]
selectTodoItems = do
todos <- runDB connInfo $ selectList [] []
return $ (\(Entity _ u) -> u) <$> todos | 140 | selectTodoItems = do
todos <- runDB connInfo $ selectList [] []
return $ (\(Entity _ u) -> u) <$> todos | 107 | false | true | 0 | 12 | 27 | 67 | 33 | 34 | null | null |
robdockins/edison | edison-core/src/Data/Edison/Seq/MyersStack.hs | mit | foldl _ e E = e | 15 | foldl _ e E = e | 15 | foldl _ e E = e | 15 | false | false | 0 | 5 | 5 | 13 | 6 | 7 | null | null |
shouya/gximemo | GxiMemo/Parser.hs | mit | parseI (PositiveLookahead p) = do
oldST <- get
m' <- parseI p
put oldST
case m' of
Just _ -> return $ Just $ MAtom ""
Nothing -> return Nothing | 162 | parseI (PositiveLookahead p) = do
oldST <- get
m' <- parseI p
put oldST
case m' of
Just _ -> return $ Just $ MAtom ""
Nothing -> return Nothing | 162 | parseI (PositiveLookahead p) = do
oldST <- get
m' <- parseI p
put oldST
case m' of
Just _ -> return $ Just $ MAtom ""
Nothing -> return Nothing | 162 | false | false | 0 | 11 | 48 | 74 | 32 | 42 | null | null |
danr/hipspec | src/HipSpec/GHC/Utils.hs | gpl-3.0 | -- | Is this Id a data or newtype constructor?
--
-- Note: cannot run isDataConWorkId on things that aren't isId,
-- then we get a panic from idDetails.
--
-- (mainly from type variables)
isDataConId :: Id -> Bool
isDataConId v = isId v && (isConLikeId v || isNewtypeConId v) | 293 | isDataConId :: Id -> Bool
isDataConId v = isId v && (isConLikeId v || isNewtypeConId v) | 87 | isDataConId v = isId v && (isConLikeId v || isNewtypeConId v) | 61 | true | true | 0 | 9 | 68 | 50 | 25 | 25 | null | null |
dillonhuff/GitVisualizer | test/AllTests.hs | gpl-2.0 | main = do
allAnalysisTests
allParserTests | 45 | main = do
allAnalysisTests
allParserTests | 45 | main = do
allAnalysisTests
allParserTests | 45 | false | false | 1 | 7 | 8 | 16 | 5 | 11 | null | null |
byteally/webapi | webapi-swagger/src/SwaggerJSONGen.hs | bsd-3-clause | petFindByTagsPath :: (FilePath, PathItem)
petFindByTagsPath = ("/pet/findByTags", mempty
& get ?~ (mempty
& SwaggerLens.tags .~ (Set.singleton "pet")
& responses .~ (mempty & responses .~ (HMSIns.fromList [(200, Inline $ mempty & description .~ "successful operation"
& schema ?~ (Inline $ mempty & (paramSchema .~ (mempty & type_ .~ SwaggerArray
& items ?~ (SwaggerItemsObject (Ref $ Reference "Pet") ) ) ) ) ),
(400, Inline $ mempty & description .~ "Invalid Tag Value" )]) )
& summary ?~ "Finds Pets by tags"
& description ?~ "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."
& operationId ?~ "findPetsByTags"
& produces ?~ MimeList ["application/json", "application/xml"]
& parameters .~ [ Inline $ mempty
& SwaggerLens.name .~ "tags"
& description ?~ "Tags to filter by"
& required ?~ True
& schema .~ (ParamOther (ParamOtherSchema ParamQuery Nothing (mempty & type_ .~ SwaggerArray
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (mempty & type_ .~ SwaggerString) ) ) ) ] ) ) | 1,537 | petFindByTagsPath :: (FilePath, PathItem)
petFindByTagsPath = ("/pet/findByTags", mempty
& get ?~ (mempty
& SwaggerLens.tags .~ (Set.singleton "pet")
& responses .~ (mempty & responses .~ (HMSIns.fromList [(200, Inline $ mempty & description .~ "successful operation"
& schema ?~ (Inline $ mempty & (paramSchema .~ (mempty & type_ .~ SwaggerArray
& items ?~ (SwaggerItemsObject (Ref $ Reference "Pet") ) ) ) ) ),
(400, Inline $ mempty & description .~ "Invalid Tag Value" )]) )
& summary ?~ "Finds Pets by tags"
& description ?~ "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."
& operationId ?~ "findPetsByTags"
& produces ?~ MimeList ["application/json", "application/xml"]
& parameters .~ [ Inline $ mempty
& SwaggerLens.name .~ "tags"
& description ?~ "Tags to filter by"
& required ?~ True
& schema .~ (ParamOther (ParamOtherSchema ParamQuery Nothing (mempty & type_ .~ SwaggerArray
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (mempty & type_ .~ SwaggerString) ) ) ) ] ) ) | 1,537 | petFindByTagsPath = ("/pet/findByTags", mempty
& get ?~ (mempty
& SwaggerLens.tags .~ (Set.singleton "pet")
& responses .~ (mempty & responses .~ (HMSIns.fromList [(200, Inline $ mempty & description .~ "successful operation"
& schema ?~ (Inline $ mempty & (paramSchema .~ (mempty & type_ .~ SwaggerArray
& items ?~ (SwaggerItemsObject (Ref $ Reference "Pet") ) ) ) ) ),
(400, Inline $ mempty & description .~ "Invalid Tag Value" )]) )
& summary ?~ "Finds Pets by tags"
& description ?~ "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."
& operationId ?~ "findPetsByTags"
& produces ?~ MimeList ["application/json", "application/xml"]
& parameters .~ [ Inline $ mempty
& SwaggerLens.name .~ "tags"
& description ?~ "Tags to filter by"
& required ?~ True
& schema .~ (ParamOther (ParamOtherSchema ParamQuery Nothing (mempty & type_ .~ SwaggerArray
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) (mempty & type_ .~ SwaggerString) ) ) ) ] ) ) | 1,495 | false | true | 0 | 36 | 661 | 329 | 174 | 155 | null | null |
AnthonyMl/pathfinding | src/main.hs | mit | intExplicitGraph g costFn algo = do
putStrLn ("length: " ++ show (List.length path))
putStrLn ("cost: " ++ show (List.foldr (\ (a, b) cost -> cost + costFn a b) 0 (List.zip (ExplicitGraph.start g : rpath) rpath)))
putStrLn (show (ExplicitGraph.start g : rpath))
putStrLn ""
where
(_, path) = algo g
rpath = List.reverse path
| 344 | printExplicitGraph g costFn algo = do
putStrLn ("length: " ++ show (List.length path))
putStrLn ("cost: " ++ show (List.foldr (\ (a, b) cost -> cost + costFn a b) 0 (List.zip (ExplicitGraph.start g : rpath) rpath)))
putStrLn (show (ExplicitGraph.start g : rpath))
putStrLn ""
where
(_, path) = algo g
rpath = List.reverse path | 344 | printExplicitGraph g costFn algo = do
putStrLn ("length: " ++ show (List.length path))
putStrLn ("cost: " ++ show (List.foldr (\ (a, b) cost -> cost + costFn a b) 0 (List.zip (ExplicitGraph.start g : rpath) rpath)))
putStrLn (show (ExplicitGraph.start g : rpath))
putStrLn ""
where
(_, path) = algo g
rpath = List.reverse path | 344 | false | false | 1 | 18 | 73 | 173 | 82 | 91 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.