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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sitewisely/zellige | src/Data/Geometry/Clip/Internal/LineLiangBarsky.hs | apache-2.0 | calcPAndQ :: TypesGeography.BoundingBox -> TypesGeography.GeoStorableLine -> DxAndDy -> Edge -> PAndQ
calcPAndQ (TypesGeography.BoundingBox minX minY maxX maxY) (TypesGeography.GeoStorableLine (Geospatial.PointXY x1 y1) _) (DxAndDy dX dY) e =
case e of
LeftEdge -> PAndQ (-1 * dX) (x1 - minX)
RightEdge -> PAndQ dX (maxX - x1)
BottomEdge -> PAndQ (-1 * dY) (y1 - minY)
TopEdge -> PAndQ dY (maxY - y1) | 424 | calcPAndQ :: TypesGeography.BoundingBox -> TypesGeography.GeoStorableLine -> DxAndDy -> Edge -> PAndQ
calcPAndQ (TypesGeography.BoundingBox minX minY maxX maxY) (TypesGeography.GeoStorableLine (Geospatial.PointXY x1 y1) _) (DxAndDy dX dY) e =
case e of
LeftEdge -> PAndQ (-1 * dX) (x1 - minX)
RightEdge -> PAndQ dX (maxX - x1)
BottomEdge -> PAndQ (-1 * dY) (y1 - minY)
TopEdge -> PAndQ dY (maxY - y1) | 424 | calcPAndQ (TypesGeography.BoundingBox minX minY maxX maxY) (TypesGeography.GeoStorableLine (Geospatial.PointXY x1 y1) _) (DxAndDy dX dY) e =
case e of
LeftEdge -> PAndQ (-1 * dX) (x1 - minX)
RightEdge -> PAndQ dX (maxX - x1)
BottomEdge -> PAndQ (-1 * dY) (y1 - minY)
TopEdge -> PAndQ dY (maxY - y1) | 322 | false | true | 0 | 11 | 85 | 176 | 89 | 87 | null | null |
anthony-coble/puzzle | app/puzzle_cuda.hs | bsd-3-clause | rotate tile =
let (a, b, c, d) = unlift tile :: (Exp Edge, Exp Edge, Exp Edge, Exp Edge)
in
lift (d, a, b, c) :: Exp (Edge, Edge, Edge, Edge) | 147 | rotate tile =
let (a, b, c, d) = unlift tile :: (Exp Edge, Exp Edge, Exp Edge, Exp Edge)
in
lift (d, a, b, c) :: Exp (Edge, Edge, Edge, Edge) | 147 | rotate tile =
let (a, b, c, d) = unlift tile :: (Exp Edge, Exp Edge, Exp Edge, Exp Edge)
in
lift (d, a, b, c) :: Exp (Edge, Edge, Edge, Edge) | 147 | false | false | 0 | 10 | 37 | 96 | 52 | 44 | null | null |
plindbe2/xmonad-windownames | src/XMonad/Actions/WindowNames.hs | bsd-3-clause | -- | Modifed 'XMonad.Hooks.DynamicLog.dynamicLogString' which takes an
-- additional WindowSet to Map of WorkspaceId to String.
dynamicLogStringMap :: (WindowSet -> X (M.Map WorkspaceId String)) -> PP -> X String
dynamicLogStringMap wsIdMap pp = do
winset <- gets windowset
urgents <- readUrgents
sort' <- ppSort pp
-- layout description
let ld = description . W.layout . W.workspace . W.current $ winset
-- workspace list
ws <- pprWindowSetMap wsIdMap sort' urgents pp winset
-- window title
wt <- maybe (return "") (fmap show . getName) . W.peek $ winset
-- run extra loggers, ignoring any that generate errors.
extras <- mapM (`catchX` return Nothing) $ ppExtras pp
return $ encodeString . sepBy (ppSep pp) . ppOrder pp $
[ ws
, ppLayout pp ld
, ppTitle pp $ ppTitleSanitize pp wt
]
++ catMaybes extras
-- | Format the workspace information | 1,020 | dynamicLogStringMap :: (WindowSet -> X (M.Map WorkspaceId String)) -> PP -> X String
dynamicLogStringMap wsIdMap pp = do
winset <- gets windowset
urgents <- readUrgents
sort' <- ppSort pp
-- layout description
let ld = description . W.layout . W.workspace . W.current $ winset
-- workspace list
ws <- pprWindowSetMap wsIdMap sort' urgents pp winset
-- window title
wt <- maybe (return "") (fmap show . getName) . W.peek $ winset
-- run extra loggers, ignoring any that generate errors.
extras <- mapM (`catchX` return Nothing) $ ppExtras pp
return $ encodeString . sepBy (ppSep pp) . ppOrder pp $
[ ws
, ppLayout pp ld
, ppTitle pp $ ppTitleSanitize pp wt
]
++ catMaybes extras
-- | Format the workspace information | 890 | dynamicLogStringMap wsIdMap pp = do
winset <- gets windowset
urgents <- readUrgents
sort' <- ppSort pp
-- layout description
let ld = description . W.layout . W.workspace . W.current $ winset
-- workspace list
ws <- pprWindowSetMap wsIdMap sort' urgents pp winset
-- window title
wt <- maybe (return "") (fmap show . getName) . W.peek $ winset
-- run extra loggers, ignoring any that generate errors.
extras <- mapM (`catchX` return Nothing) $ ppExtras pp
return $ encodeString . sepBy (ppSep pp) . ppOrder pp $
[ ws
, ppLayout pp ld
, ppTitle pp $ ppTitleSanitize pp wt
]
++ catMaybes extras
-- | Format the workspace information | 805 | true | true | 0 | 14 | 315 | 258 | 125 | 133 | null | null |
luzhuomi/cpp-obs | Language/C/Obfuscate/SSA.hs | apache-2.0 | buildDF' :: (DTree, DTreeMap, SDom, CFG) -> DFTable
buildDF' (dtree, pcm, sdom, cfg) =
-- traversing the dtree in post order
-- build the df1 and df, for leaf nodes df == df1
-- for non-leaf nodes, df = df1 \union dfup(c) for all child node c.
-- DF1(a) is the local dominance frontier for node a.
-- DF1(a) = { b | b \in succ(a), not (a sdom b) }
-- e.g. DF1(3) = { 2 } because 2 \in succ(3), but not (3 sdom 2)
-- Lemma: Let b \in succ(a), a = idom(b) iff a sdom b
-- Hence DF1 can be computed easily via the following
-- DF1(a) = { b | b \in succ(a), a != idom(b) }
-- DFup(a) is the upwards dominance frontier for node a.
-- DFup(a) = { b | b \in DF(a), not (idom(a) sdom b) }
-- Similar to DF1
-- DFup can be computed easily via the following
-- DFup(a) = { b | b \in DF(a), idom(a) = c, idom(b) != c }
-- DF(a) is the dominance frontier for node a.
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- Lemma: Let a be a leaf node in dom tree, then DF(a) == DF1(a)
--
-- WAIT, the reference says
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DFup(c) }
-- They are they same!
-- by definition of DFup(c)
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (idom(c) sdom b) }
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- we don't need to compute DFup -- todo, remove DFup or use it in computing DF(a)
let po :: [Ident]
po = postOrder dtree
idoms :: M.Map Ident Ident
idoms = foldl (\m (p,cs) -> foldl (\m' c -> M.insert c p m') m cs) M.empty (M.toList pcm)
findDF1 :: Ident -> DFTable -> [Ident]
findDF1 a dft = case M.lookup a cfg of
{ Nothing -> []
; Just n ->
let bs = succs n
idoms = idom dft
df1 = concatMap (\b -> case M.lookup b idoms of
{ Nothing -> [b] -- shouldn't be [], b has no idoms, means it is 0
; Just idom | a == idom -> []
| otherwise -> [b]
}) bs
-- io = unsafePerformIO $ print a >> print idoms >> print bs >> print df1
in df1
}
findDFup :: Ident -> DFTable -> [Ident]
findDFup a dftable = case M.lookup a (df dftable) of
{ Nothing -> []
; Just bs ->
concatMap (\b ->
case (M.lookup b idoms, M.lookup a idoms) of
{ (Just idb, Just ida) | idb /= ida -> [b]
; _ -> []
}) bs
}
findDF :: Ident -> [Ident] -> DFTable -> [Ident]
findDF a a_df1 dftable =
let {- a_df1 = case M.lookup a (df1 dftable) of
{ Nothing -> []
; Just bs -> bs } -} -- a_df1 needs to be passed in because dftable is partial
a_sdom b = case M.lookup a sdom of
{ Nothing -> False
; Just doms -> b `S.member` doms
}
cs = case M.lookup a pcm of
{ Nothing -> []
; Just xs -> xs
}
bs = concatMap (\c -> case M.lookup c (df dftable) of
{ Nothing -> []
; Just ys -> [ y | y <- ys, not (a_sdom y)]
}
) cs
in a_df1 ++ bs
empDFT = DFTable idoms M.empty M.empty M.empty
-- io = unsafePerformIO $ print po >> print cfg
in foldl (\dft id ->
let df1' = findDF1 id dft
dfup' = findDFup id dft
df' = findDF id df1' dft
(DFTable idoms df1s dfups dfs) = dft
in dft{ df1 = (M.insert id df1' df1s)
, dfup = (M.insert id dfup' dfups)
, df = (M.insert id df' dfs)
}
) empDFT po | 4,040 | buildDF' :: (DTree, DTreeMap, SDom, CFG) -> DFTable
buildDF' (dtree, pcm, sdom, cfg) =
-- traversing the dtree in post order
-- build the df1 and df, for leaf nodes df == df1
-- for non-leaf nodes, df = df1 \union dfup(c) for all child node c.
-- DF1(a) is the local dominance frontier for node a.
-- DF1(a) = { b | b \in succ(a), not (a sdom b) }
-- e.g. DF1(3) = { 2 } because 2 \in succ(3), but not (3 sdom 2)
-- Lemma: Let b \in succ(a), a = idom(b) iff a sdom b
-- Hence DF1 can be computed easily via the following
-- DF1(a) = { b | b \in succ(a), a != idom(b) }
-- DFup(a) is the upwards dominance frontier for node a.
-- DFup(a) = { b | b \in DF(a), not (idom(a) sdom b) }
-- Similar to DF1
-- DFup can be computed easily via the following
-- DFup(a) = { b | b \in DF(a), idom(a) = c, idom(b) != c }
-- DF(a) is the dominance frontier for node a.
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- Lemma: Let a be a leaf node in dom tree, then DF(a) == DF1(a)
--
-- WAIT, the reference says
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DFup(c) }
-- They are they same!
-- by definition of DFup(c)
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (idom(c) sdom b) }
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- we don't need to compute DFup -- todo, remove DFup or use it in computing DF(a)
let po :: [Ident]
po = postOrder dtree
idoms :: M.Map Ident Ident
idoms = foldl (\m (p,cs) -> foldl (\m' c -> M.insert c p m') m cs) M.empty (M.toList pcm)
findDF1 :: Ident -> DFTable -> [Ident]
findDF1 a dft = case M.lookup a cfg of
{ Nothing -> []
; Just n ->
let bs = succs n
idoms = idom dft
df1 = concatMap (\b -> case M.lookup b idoms of
{ Nothing -> [b] -- shouldn't be [], b has no idoms, means it is 0
; Just idom | a == idom -> []
| otherwise -> [b]
}) bs
-- io = unsafePerformIO $ print a >> print idoms >> print bs >> print df1
in df1
}
findDFup :: Ident -> DFTable -> [Ident]
findDFup a dftable = case M.lookup a (df dftable) of
{ Nothing -> []
; Just bs ->
concatMap (\b ->
case (M.lookup b idoms, M.lookup a idoms) of
{ (Just idb, Just ida) | idb /= ida -> [b]
; _ -> []
}) bs
}
findDF :: Ident -> [Ident] -> DFTable -> [Ident]
findDF a a_df1 dftable =
let {- a_df1 = case M.lookup a (df1 dftable) of
{ Nothing -> []
; Just bs -> bs } -} -- a_df1 needs to be passed in because dftable is partial
a_sdom b = case M.lookup a sdom of
{ Nothing -> False
; Just doms -> b `S.member` doms
}
cs = case M.lookup a pcm of
{ Nothing -> []
; Just xs -> xs
}
bs = concatMap (\c -> case M.lookup c (df dftable) of
{ Nothing -> []
; Just ys -> [ y | y <- ys, not (a_sdom y)]
}
) cs
in a_df1 ++ bs
empDFT = DFTable idoms M.empty M.empty M.empty
-- io = unsafePerformIO $ print po >> print cfg
in foldl (\dft id ->
let df1' = findDF1 id dft
dfup' = findDFup id dft
df' = findDF id df1' dft
(DFTable idoms df1s dfups dfs) = dft
in dft{ df1 = (M.insert id df1' df1s)
, dfup = (M.insert id dfup' dfups)
, df = (M.insert id df' dfs)
}
) empDFT po | 4,040 | buildDF' (dtree, pcm, sdom, cfg) =
-- traversing the dtree in post order
-- build the df1 and df, for leaf nodes df == df1
-- for non-leaf nodes, df = df1 \union dfup(c) for all child node c.
-- DF1(a) is the local dominance frontier for node a.
-- DF1(a) = { b | b \in succ(a), not (a sdom b) }
-- e.g. DF1(3) = { 2 } because 2 \in succ(3), but not (3 sdom 2)
-- Lemma: Let b \in succ(a), a = idom(b) iff a sdom b
-- Hence DF1 can be computed easily via the following
-- DF1(a) = { b | b \in succ(a), a != idom(b) }
-- DFup(a) is the upwards dominance frontier for node a.
-- DFup(a) = { b | b \in DF(a), not (idom(a) sdom b) }
-- Similar to DF1
-- DFup can be computed easily via the following
-- DFup(a) = { b | b \in DF(a), idom(a) = c, idom(b) != c }
-- DF(a) is the dominance frontier for node a.
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- Lemma: Let a be a leaf node in dom tree, then DF(a) == DF1(a)
--
-- WAIT, the reference says
-- DF(a) = DF1(a) \union { b | c \in child(a), b \in DFup(c) }
-- They are they same!
-- by definition of DFup(c)
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (idom(c) sdom b) }
-- = DF1(a) \union { b | c \in child(a), b \in DF(c), not (a sdom b) }
-- we don't need to compute DFup -- todo, remove DFup or use it in computing DF(a)
let po :: [Ident]
po = postOrder dtree
idoms :: M.Map Ident Ident
idoms = foldl (\m (p,cs) -> foldl (\m' c -> M.insert c p m') m cs) M.empty (M.toList pcm)
findDF1 :: Ident -> DFTable -> [Ident]
findDF1 a dft = case M.lookup a cfg of
{ Nothing -> []
; Just n ->
let bs = succs n
idoms = idom dft
df1 = concatMap (\b -> case M.lookup b idoms of
{ Nothing -> [b] -- shouldn't be [], b has no idoms, means it is 0
; Just idom | a == idom -> []
| otherwise -> [b]
}) bs
-- io = unsafePerformIO $ print a >> print idoms >> print bs >> print df1
in df1
}
findDFup :: Ident -> DFTable -> [Ident]
findDFup a dftable = case M.lookup a (df dftable) of
{ Nothing -> []
; Just bs ->
concatMap (\b ->
case (M.lookup b idoms, M.lookup a idoms) of
{ (Just idb, Just ida) | idb /= ida -> [b]
; _ -> []
}) bs
}
findDF :: Ident -> [Ident] -> DFTable -> [Ident]
findDF a a_df1 dftable =
let {- a_df1 = case M.lookup a (df1 dftable) of
{ Nothing -> []
; Just bs -> bs } -} -- a_df1 needs to be passed in because dftable is partial
a_sdom b = case M.lookup a sdom of
{ Nothing -> False
; Just doms -> b `S.member` doms
}
cs = case M.lookup a pcm of
{ Nothing -> []
; Just xs -> xs
}
bs = concatMap (\c -> case M.lookup c (df dftable) of
{ Nothing -> []
; Just ys -> [ y | y <- ys, not (a_sdom y)]
}
) cs
in a_df1 ++ bs
empDFT = DFTable idoms M.empty M.empty M.empty
-- io = unsafePerformIO $ print po >> print cfg
in foldl (\dft id ->
let df1' = findDF1 id dft
dfup' = findDFup id dft
df' = findDF id df1' dft
(DFTable idoms df1s dfups dfs) = dft
in dft{ df1 = (M.insert id df1' df1s)
, dfup = (M.insert id dfup' dfups)
, df = (M.insert id df' dfs)
}
) empDFT po | 3,988 | false | true | 0 | 25 | 1,697 | 819 | 442 | 377 | null | null |
xenog/haskoin | src/Network/Haskoin/Test/Crypto.hs | unlicense | -- | Arbitrary compressed private key
arbitraryPrvKeyC :: Gen PrvKeyC
arbitraryPrvKeyC = makePrvKeyC <$> arbitrary | 114 | arbitraryPrvKeyC :: Gen PrvKeyC
arbitraryPrvKeyC = makePrvKeyC <$> arbitrary | 76 | arbitraryPrvKeyC = makePrvKeyC <$> arbitrary | 44 | true | true | 0 | 6 | 14 | 25 | 11 | 14 | null | null |
bgamari/text | tests/Tests/Properties.hs | bsd-2-clause | tb_hexadecimal_int64 (a::Int64) = tb_hex a | 42 | tb_hexadecimal_int64 (a::Int64) = tb_hex a | 42 | tb_hexadecimal_int64 (a::Int64) = tb_hex a | 42 | false | false | 0 | 7 | 4 | 19 | 9 | 10 | null | null |
snoyberg/photosorter | fay/Language/Fay/JQuery.hs | bsd-2-clause | closestWithContext :: String -> String -> JQuery -> Fay JQuery
closestWithContext = ffi "%3['closest'](%1, %2)" | 111 | closestWithContext :: String -> String -> JQuery -> Fay JQuery
closestWithContext = ffi "%3['closest'](%1, %2)" | 111 | closestWithContext = ffi "%3['closest'](%1, %2)" | 48 | false | true | 0 | 8 | 14 | 29 | 14 | 15 | null | null |
molysgaard/Sirkel | examples/TestClient.hs | bsd-3-clause | _PROGRAM_NAME :: String
_PROGRAM_NAME = "TestClient" | 52 | _PROGRAM_NAME :: String
_PROGRAM_NAME = "TestClient" | 52 | _PROGRAM_NAME = "TestClient" | 28 | false | true | 0 | 6 | 5 | 18 | 7 | 11 | null | null |
camiara/uvaSTesting15 | Week 1/HW01Tests.hs | mit | -- Exercise 5 -----------------------------------------
ex5Tests :: [Test]
ex5Tests = [] | 89 | ex5Tests :: [Test]
ex5Tests = [] | 32 | ex5Tests = [] | 13 | true | true | 0 | 7 | 10 | 24 | 11 | 13 | null | null |
todesking/YampaSynth | src/Main/OpenAL.hs | bsd-3-clause | printErrs :: String -> [String] -> IO ()
printErrs s x = when (not $ null x) . putStrLn $ s ++ ": " ++ show x | 109 | printErrs :: String -> [String] -> IO ()
printErrs s x = when (not $ null x) . putStrLn $ s ++ ": " ++ show x | 109 | printErrs s x = when (not $ null x) . putStrLn $ s ++ ": " ++ show x | 68 | false | true | 0 | 12 | 26 | 64 | 31 | 33 | null | null |
neothemachine/monadiccp | src/Control/CP/FD/SimpleFD.hs | bsd-3-clause | trueSpec = FDSpecInfoBool {fdspBoolSpec=const Nothing,fdspBoolVar=Nothing,fdspBoolVal=Just $ BoolConst True,fdspBoolTypes=Set.empty} | 132 | trueSpec = FDSpecInfoBool {fdspBoolSpec=const Nothing,fdspBoolVar=Nothing,fdspBoolVal=Just $ BoolConst True,fdspBoolTypes=Set.empty} | 132 | trueSpec = FDSpecInfoBool {fdspBoolSpec=const Nothing,fdspBoolVar=Nothing,fdspBoolVal=Just $ BoolConst True,fdspBoolTypes=Set.empty} | 132 | false | false | 0 | 8 | 7 | 44 | 25 | 19 | null | null |
jthornber/language-c-ejt | test-framework/Language/C/Test/ParseTests.hs | bsd-3-clause | compileTestTemplate :: Test
compileTestTemplate = Test
{
testName = "compile",
testDescr = "compile the given file using gcc",
preferredScale = Kilo,
inputUnit = linesOfCode
} | 195 | compileTestTemplate :: Test
compileTestTemplate = Test
{
testName = "compile",
testDescr = "compile the given file using gcc",
preferredScale = Kilo,
inputUnit = linesOfCode
} | 195 | compileTestTemplate = Test
{
testName = "compile",
testDescr = "compile the given file using gcc",
preferredScale = Kilo,
inputUnit = linesOfCode
} | 167 | false | true | 0 | 7 | 44 | 41 | 24 | 17 | null | null |
TomMD/ghc | compiler/prelude/PrelNames.hs | bsd-3-clause | reset_RDR = varQual_RDR rEAD_PREC (fsLit "reset") | 64 | reset_RDR = varQual_RDR rEAD_PREC (fsLit "reset") | 64 | reset_RDR = varQual_RDR rEAD_PREC (fsLit "reset") | 64 | false | false | 0 | 7 | 20 | 17 | 8 | 9 | null | null |
ezyang/ghc | compiler/ghci/ByteCodeAsm.hs | bsd-3-clause | mkLitI i = [fromIntegral i :: Word] | 35 | mkLitI i = [fromIntegral i :: Word] | 35 | mkLitI i = [fromIntegral i :: Word] | 35 | false | false | 1 | 7 | 6 | 22 | 9 | 13 | null | null |
lukexi/ghc-7.8-arm64 | compiler/main/HscMain.hs | bsd-3-clause | tryNewCodeGen :: HscEnv -> Module -> [TyCon]
-> CollectedCCs
-> [StgBinding]
-> HpcInfo
-> IO (Stream IO CmmGroup ())
-- Note we produce a 'Stream' of CmmGroups, so that the
-- backend can be run incrementally. Otherwise it generates all
-- the C-- up front, which has a significant space cost.
tryNewCodeGen hsc_env this_mod data_tycons
cost_centre_info stg_binds hpc_info = do
let dflags = hsc_dflags hsc_env
let cmm_stream :: Stream IO CmmGroup ()
cmm_stream = {-# SCC "StgCmm" #-}
StgCmm.codeGen dflags this_mod data_tycons
cost_centre_info stg_binds hpc_info
-- codegen consumes a stream of CmmGroup, and produces a new
-- stream of CmmGroup (not necessarily synchronised: one
-- CmmGroup on input may produce many CmmGroups on output due
-- to proc-point splitting).
let dump1 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm
"Cmm produced by new codegen" (ppr a)
return a
ppr_stream1 = Stream.mapM dump1 cmm_stream
-- We are building a single SRT for the entire module, so
-- we must thread it through all the procedures as we cps-convert them.
us <- mkSplitUniqSupply 'S'
-- When splitting, we generate one SRT per split chunk, otherwise
-- we generate one SRT for the whole module.
let
pipeline_stream
| gopt Opt_SplitObjs dflags
= {-# SCC "cmmPipeline" #-}
let run_pipeline us cmmgroup = do
let (topSRT', us') = initUs us emptySRT
(topSRT, cmmgroup) <- cmmPipeline hsc_env topSRT' cmmgroup
let srt | isEmptySRT topSRT = []
| otherwise = srtToData topSRT
return (us', srt ++ cmmgroup)
in do _ <- Stream.mapAccumL run_pipeline us ppr_stream1
return ()
| otherwise
= {-# SCC "cmmPipeline" #-}
let initTopSRT = initUs_ us emptySRT
run_pipeline = cmmPipeline hsc_env
in do topSRT <- Stream.mapAccumL run_pipeline initTopSRT ppr_stream1
Stream.yield (srtToData topSRT)
let
dump2 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm "Output Cmm" $ ppr a
return a
ppr_stream2 = Stream.mapM dump2 pipeline_stream
return ppr_stream2 | 2,462 | tryNewCodeGen :: HscEnv -> Module -> [TyCon]
-> CollectedCCs
-> [StgBinding]
-> HpcInfo
-> IO (Stream IO CmmGroup ())
tryNewCodeGen hsc_env this_mod data_tycons
cost_centre_info stg_binds hpc_info = do
let dflags = hsc_dflags hsc_env
let cmm_stream :: Stream IO CmmGroup ()
cmm_stream = {-# SCC "StgCmm" #-}
StgCmm.codeGen dflags this_mod data_tycons
cost_centre_info stg_binds hpc_info
-- codegen consumes a stream of CmmGroup, and produces a new
-- stream of CmmGroup (not necessarily synchronised: one
-- CmmGroup on input may produce many CmmGroups on output due
-- to proc-point splitting).
let dump1 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm
"Cmm produced by new codegen" (ppr a)
return a
ppr_stream1 = Stream.mapM dump1 cmm_stream
-- We are building a single SRT for the entire module, so
-- we must thread it through all the procedures as we cps-convert them.
us <- mkSplitUniqSupply 'S'
-- When splitting, we generate one SRT per split chunk, otherwise
-- we generate one SRT for the whole module.
let
pipeline_stream
| gopt Opt_SplitObjs dflags
= {-# SCC "cmmPipeline" #-}
let run_pipeline us cmmgroup = do
let (topSRT', us') = initUs us emptySRT
(topSRT, cmmgroup) <- cmmPipeline hsc_env topSRT' cmmgroup
let srt | isEmptySRT topSRT = []
| otherwise = srtToData topSRT
return (us', srt ++ cmmgroup)
in do _ <- Stream.mapAccumL run_pipeline us ppr_stream1
return ()
| otherwise
= {-# SCC "cmmPipeline" #-}
let initTopSRT = initUs_ us emptySRT
run_pipeline = cmmPipeline hsc_env
in do topSRT <- Stream.mapAccumL run_pipeline initTopSRT ppr_stream1
Stream.yield (srtToData topSRT)
let
dump2 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm "Output Cmm" $ ppr a
return a
ppr_stream2 = Stream.mapM dump2 pipeline_stream
return ppr_stream2 | 2,257 | tryNewCodeGen hsc_env this_mod data_tycons
cost_centre_info stg_binds hpc_info = do
let dflags = hsc_dflags hsc_env
let cmm_stream :: Stream IO CmmGroup ()
cmm_stream = {-# SCC "StgCmm" #-}
StgCmm.codeGen dflags this_mod data_tycons
cost_centre_info stg_binds hpc_info
-- codegen consumes a stream of CmmGroup, and produces a new
-- stream of CmmGroup (not necessarily synchronised: one
-- CmmGroup on input may produce many CmmGroups on output due
-- to proc-point splitting).
let dump1 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm
"Cmm produced by new codegen" (ppr a)
return a
ppr_stream1 = Stream.mapM dump1 cmm_stream
-- We are building a single SRT for the entire module, so
-- we must thread it through all the procedures as we cps-convert them.
us <- mkSplitUniqSupply 'S'
-- When splitting, we generate one SRT per split chunk, otherwise
-- we generate one SRT for the whole module.
let
pipeline_stream
| gopt Opt_SplitObjs dflags
= {-# SCC "cmmPipeline" #-}
let run_pipeline us cmmgroup = do
let (topSRT', us') = initUs us emptySRT
(topSRT, cmmgroup) <- cmmPipeline hsc_env topSRT' cmmgroup
let srt | isEmptySRT topSRT = []
| otherwise = srtToData topSRT
return (us', srt ++ cmmgroup)
in do _ <- Stream.mapAccumL run_pipeline us ppr_stream1
return ()
| otherwise
= {-# SCC "cmmPipeline" #-}
let initTopSRT = initUs_ us emptySRT
run_pipeline = cmmPipeline hsc_env
in do topSRT <- Stream.mapAccumL run_pipeline initTopSRT ppr_stream1
Stream.yield (srtToData topSRT)
let
dump2 a = do dumpIfSet_dyn dflags Opt_D_dump_cmm "Output Cmm" $ ppr a
return a
ppr_stream2 = Stream.mapM dump2 pipeline_stream
return ppr_stream2 | 2,073 | true | true | 2 | 19 | 843 | 449 | 213 | 236 | null | null |
TomMD/ghc | compiler/main/DynFlags.hs | bsd-3-clause | addDepSuffix :: FilePath -> DynFlags -> DynFlags
addDepSuffix s d = d { depSuffixes = s : depSuffixes d } | 105 | addDepSuffix :: FilePath -> DynFlags -> DynFlags
addDepSuffix s d = d { depSuffixes = s : depSuffixes d } | 105 | addDepSuffix s d = d { depSuffixes = s : depSuffixes d } | 56 | false | true | 0 | 9 | 19 | 48 | 22 | 26 | null | null |
SWP-Ubau-SoSe2014-Haskell/SWPSoSe14 | src/RailEditor/Selection.hs | mit | getMinimum :: [TAC.Position] -> TAC.Position
getMinimum [] = (0,0) | 66 | getMinimum :: [TAC.Position] -> TAC.Position
getMinimum [] = (0,0) | 66 | getMinimum [] = (0,0) | 21 | false | true | 0 | 7 | 8 | 33 | 18 | 15 | null | null |
sdiehl/ghc | compiler/GHC/Stg/Stats.hs | bsd-3-clause | gatherStgStats :: [StgTopBinding] -> StatEnv
gatherStgStats binds = combineSEs (map statTopBinding binds) | 105 | gatherStgStats :: [StgTopBinding] -> StatEnv
gatherStgStats binds = combineSEs (map statTopBinding binds) | 105 | gatherStgStats binds = combineSEs (map statTopBinding binds) | 60 | false | true | 0 | 7 | 11 | 35 | 17 | 18 | null | null |
athanclark/tries | src/Data/Trie/Pseudo.hs | bsd-3-clause | -- | The meet of two @PseudoTrie@s
intersectionWith :: (Eq t) =>
(a -> b -> c)
-> PseudoTrie t a
-> PseudoTrie t b
-> PseudoTrie t c
intersectionWith _ _ Nil = Nil | 234 | intersectionWith :: (Eq t) =>
(a -> b -> c)
-> PseudoTrie t a
-> PseudoTrie t b
-> PseudoTrie t c
intersectionWith _ _ Nil = Nil | 199 | intersectionWith _ _ Nil = Nil | 30 | true | true | 0 | 9 | 105 | 66 | 33 | 33 | null | null |
michalkonecny/aern | aern-mpfr-rounded/src/Numeric/AERN/RealArithmetic/Basis/MPFR/Conversion.hs | bsd-3-clause | dblMinBound, dblMaxBound :: Double
dblMinBound = encodeFloat (negate $ dblSigMaxBound - 1) dblExpMaxBound | 105 | dblMinBound, dblMaxBound :: Double
dblMinBound = encodeFloat (negate $ dblSigMaxBound - 1) dblExpMaxBound | 105 | dblMinBound = encodeFloat (negate $ dblSigMaxBound - 1) dblExpMaxBound | 70 | false | true | 2 | 8 | 12 | 40 | 17 | 23 | null | null |
UBMLtonGroup/timberc | src/Env.hs | bsd-3-clause | a = TId (name0 "a") | 41 | a = TId (name0 "a") | 41 | a = TId (name0 "a") | 41 | false | false | 0 | 7 | 26 | 15 | 7 | 8 | null | null |
kim/amazonka | amazonka-cloudwatch/gen/Network/AWS/CloudWatch/DescribeAlarms.hs | mpl-2.0 | -- | The maximum number of alarm descriptions to retrieve.
daMaxRecords :: Lens' DescribeAlarms (Maybe Natural)
daMaxRecords = lens _daMaxRecords (\s a -> s { _daMaxRecords = a }) . mapping _Nat | 194 | daMaxRecords :: Lens' DescribeAlarms (Maybe Natural)
daMaxRecords = lens _daMaxRecords (\s a -> s { _daMaxRecords = a }) . mapping _Nat | 135 | daMaxRecords = lens _daMaxRecords (\s a -> s { _daMaxRecords = a }) . mapping _Nat | 82 | true | true | 0 | 10 | 31 | 53 | 28 | 25 | null | null |
gcross/habit-of-fate | sources/tests/test-server.hs | agpl-3.0 | main ∷ HasCallStack ⇒ IO ()
main = doMain
------------------------------------------------------------------------------
[ testGroup "HabitOfFate.Server"
------------------------------------------------------------------------------
[ testGroup "JSON API" $
----------------------------------------------------------------------------
let apiTestCase ∷ String → (SessionIO ()) → TestTree
apiTestCase test_name action =
(
createAccount "bitslayer" "password" Testing "localhost"
>=>
(fromMaybe (error "Unable to create account.") >>> runSessionT action)
)
|> serverTestCase test_name
in
------------------------------------------------------------------------
[ testGroup "Missing username/password" $
------------------------------------------------------------------------
let testMissing test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testMissing "Missing username" "create?password=foobar"
, testMissing "Missing password" "create?username=foobar"
]
, testGroup "Log in"
[ testMissing "Missing username" "login?password=foobar"
, testMissing "Missing password" "login?username=foobar"
]
]
------------------------------------------------------------------------
, testGroup "Empty username/password" $
------------------------------------------------------------------------
let testEmpty test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testEmpty "Empty username" "create?username="
, testEmpty "Empty password" "create?password="
]
]
------------------------------------------------------------------------
, apiTestCase "Logging out makes habits forbidden to access." $ do
------------------------------------------------------------------------
logout
try getHabits >>= \case
Left (UnexpectedStatus _ 403) → pure ()
Left e → throwM e
_ → assertFailure "No exception raised."
------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506")
>>=
(@?= Nothing)
------------------------------------------------------------------------
, testGroup "putGroup"
------------------------------------------------------------------------
[ apiTestCase "Putting a group and then fetching it returns the group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroup test_group_id >>= (@?= Just test_group)
--------------------------------------------------------------------
, apiTestCase "Putting a group causes fetching all groups to return a singleton map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroups >>= (@?= [(test_group_id, test_group)])
--------------------------------------------------------------------
, apiTestCase "Putting a group, replacing it, and then fetching all groups returns the replaced group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
replaceGroup test_group_id test_group_2
getGroups >>= (@?= [(test_group_id, test_group_2)])
]
------------------------------------------------------------------------
, testGroup "putHabit"
------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
--------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
replaceHabit test_habit_id test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit_2)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit with missing groups creates habit with no groups" $ do
--------------------------------------------------------------------
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
--------------------------------------------------------------------
, apiTestCase "Putting a habit with existing group returns expected habit" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
]
------------------------------------------------------------------------
, testGroup "deleteGroup"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing group returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteGroup test_group_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a group then deleting it returns ResourceDeleted and causes fetching all groups to return an empty map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getGroups >>= (view items_count_ >>> (@?= 0))
--------------------------------------------------------------------
, apiTestCase "Deleting a group removes it from all habits" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
]
------------------------------------------------------------------------
, testGroup "deleteHabit"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing habit returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteHabit test_habit_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a habit then deleting it returns ResourceDeleted and causes fetching all habits to return an empty map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
deleteHabit test_habit_id >>= (@?= ResourceDeleted)
getHabits >>= (view items_count_ >>> (@?= 0))
]
----------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
----------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
----------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
----------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506") >>= (@?= Nothing)
----------------------------------------------------------------------------
, testGroup "putHabit"
----------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
------------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
------------------------------------------------------------------------
, testGroup "Putting two habits causes them to be returned in order of creation" $
------------------------------------------------------------------------
[ apiTestCase "Test habit 1 followed by test habit 2" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit), (test_habit_id_2, test_habit_2)])
------------------------------------------------------------------------
, apiTestCase "Test habit 2 followed by test habit 1" $ do
------------------------------------------------------------------------
createHabit test_habit_id_2 test_habit_2
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id_2, test_habit_2), (test_habit_id, test_habit)])
]
------------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [FailureResult])
, (test_habit_id_2, [SuccessResult])
, (test_habit_id_2, [])
]
getMarks >>= (@?=
[ Mark FailureResult $ test_habit ^. importance_
, Mark SuccessResult $ test_habit_2 ^. difficulty_
])
------------------------------------------------------------------------
, testCase "Putting a habit causes the accounts to be written" $ do
------------------------------------------------------------------------
accounts_changed_signal ← newTVarIO False
(makeAppRunningInTestMode
<$> newTVarIO mempty
<*> pure accounts_changed_signal
) >>=
flip withApplication (
\port → do
session_info ← fromJust <$> createAccount "bitslayer" "password" Testing "localhost" port
flip runSessionT session_info $ createHabit test_habit_id test_habit
)
atomically (readTVar accounts_changed_signal) >>= (@?= True)
]
----------------------------------------------------------------------------
, testGroup "markHabits"
----------------------------------------------------------------------------
[ apiTestCase "Marking a habit gets the right marks" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [SuccessResult])
, (test_habit_id_2, [FailureResult])
, (test_habit_id, [])
]
getMarks >>= (@?=
[ Mark SuccessResult $ test_habit ^. difficulty_
, Mark FailureResult $ test_habit_2 ^. importance_
])
]
----------------------------------------------------------------------------
, testGroup "configuration"
----------------------------------------------------------------------------
[ apiTestCase "Put then get" $ do
------------------------------------------------------------------------
Configuration old_tzlabel ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
getConfiguration >>= (@?= new_configuration)
------------------------------------------------------------------------
, apiTestCase "Put then reset" $ do
------------------------------------------------------------------------
old_configuration@(Configuration old_tzlabel) ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
resetConfiguration
getConfiguration >>= (@?= old_configuration)
]
----------------------------------------------------------------------------
, testGroup "deadlines"
----------------------------------------------------------------------------
[ apiTestCase "Two habits with neither having any deadlines" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [])
------------------------------------------------------------------------
, apiTestCase "Two habits with one having a Once deadline" $ do
------------------------------------------------------------------------
createHabit test_habit_id (test_habit & frequency_ .~ (Once (Just (dayHour 0 0))))
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, []), (test_habit_id_2, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getMarks
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, [SuccessResult, FailureResult])]
>>= (@?=
[ Mark SuccessResult $ test_habit_2 ^. difficulty_
, Mark SuccessResult $ test_habit ^. difficulty_
])
getDeadlines >>= (@?= [])
getHabit test_habit_id >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "Three habits all having Once deadlines" $ do
------------------------------------------------------------------------
let test_habit_1_once = test_habit_1 & frequency_ .~ (Once (Just (dayHour 0 0)))
test_habit_2_once = test_habit_2 & frequency_ .~ (Once (Just (dayHour 1 1)))
test_habit_3_once = test_habit_3 & frequency_ .~ (Once (Just (dayHour 2 2)))
createHabit test_habit_id_1 test_habit_1_once
createHabit test_habit_id_2 test_habit_2_once
createHabit test_habit_id_3 test_habit_3_once
getDeadlines >>= (@?=
[ (test_habit_id_1, [dayHour 0 0])
, (test_habit_id_2, [dayHour 1 1])
, (test_habit_id_3, [dayHour 2 2])
])
markHabits
[ (test_habit_id_1, [])
, (test_habit_id_2, [FailureResult])
, (test_habit_id_3, [SuccessResult, FailureResult])
]
>>= (@?=
[ Mark FailureResult $ test_habit_2 ^. importance_
, Mark SuccessResult $ test_habit_3 ^. difficulty_
])
getDeadlines >>= (@?= [(test_habit_id_1, [dayHour 0 0])])
getHabit test_habit_id_1 >>= (@?= Just test_habit_1_once)
getHabit test_habit_id_2 >>= (@?= Nothing)
getHabit test_habit_id_3 >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "One habit repeated daily" $ do
------------------------------------------------------------------------
putConfiguration $ Configuration Etc__UTC
createHabit test_habit_id
(test_habit &
frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour 0 0) (Daily 1)
)
LocalTime (ModifiedJulianDay d) _ ← liftIO getCurrentTime <&> utcToLocalTime utc
getDeadlines >>= (@?= [(test_habit_id, [dayHour (d-i) 0 | i ← [0,1,2]])])
markHabits [(test_habit_id, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit ^. difficulty_ ])
getDeadlines >>= (@?= [])
new_test_habit ← getHabit test_habit_id >>= maybe (assertFailure "Habit not found.") pure
new_test_habit @?= (
test_habit
& maybe_last_marked_ .~ new_test_habit ^. maybe_last_marked_
& frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour (fromInteger (d+1)) 0) (Daily 1)
)
last_marked_time ←
maybe
(assertFailure "Habit was not marked.")
pure
(new_test_habit ^. maybe_last_marked_)
current_time ← liftIO getCurrentTime <&> utcToLocalTime utc
assertBool "Current time was before last marked time." (current_time >= last_marked_time)
]
]
----------------------------------------------------------------------------
, testGroup "Web" $
----------------------------------------------------------------------------
[ testGroup "Redirections" $
------------------------------------------------------------------------
[ webTestCase "GET / redirects to /habits" $ do
(response, _) ← requestDocument "/" $ setRequestMethod "GET"
assertRedirectsTo response "/habits"
, webTestCase "GET /habits redirects to /login" $ do
(response, _) ← requestDocument "/habits" $ setRequestMethod "GET"
assertRedirectsTo response "/login"
]
------------------------------------------------------------------------
, testGroup "Login page" $
------------------------------------------------------------------------
[ webTestCase "GET /login returns login page" $ do
(_, tags) ← requestDocument "/login" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Login"
, webTestCase "POST /login for non-existent user returns login page withe error" $ do
(_, tags) ← requestDocument "/login" $
setRequestBodyURLEncoded [("username","username"), ("password","password")]
assertPageTitleEquals tags "Habit of Fate - Login"
assertTextIs tags "error-message" "No account has that username."
]
------------------------------------------------------------------------
, testGroup "Create page" $
------------------------------------------------------------------------
[ webTestCase "GET /create returns account creation page" $ do
(_, tags) ← requestDocument "/create" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Account Creation"
, webTestCase "POST /create with fields filled in redirects to /" $ do
(response, _) ← createTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account causes / to load the habits page" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating an account then logging in redirects to /" $ do
_ ← createTestAccount "username" "password"
(response, _) ← loginTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account makes /habits display the list of habits" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating a conflicting account displays an error message" $ do
_ ← createTestAccount "username" "password"
(response, tags) ← createTestAccount "username" "password"
getResponseStatusCode response @?= 409
assertTextIs tags "error-message" "This account already exists."
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the group edit page for an existing group." $ do
_ ← createTestAccount "username" "password"
createGroupViaWeb test_group_id test_group
(response, tags) ←
requestDocument ([i|/groups/#{UUID.toText test_group_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractGroup tags >>= (@?= test_group)
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the habit edit page for an existing habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_2 test_habit_2
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_2}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_2)
, webTestCase "Open the habit edit page for a once habit with deadline." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_once test_habit_once
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_once}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_once)
, webTestCase "Open the habit edit page for a daily repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_daily
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_daily)
, webTestCase "Open the habit edit page for a weekly repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_weekly
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_weekly)
, webTestCase "Open the habit edit page for a habit with a nontrivial last marked field." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_with_last_marked test_habit_with_last_marked
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_with_last_marked}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_with_last_marked)
, webTestCase "Create a habit with a missing group via. web then open." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_group test_habit_group
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_group}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= (test_habit_group & (group_membership_ .~ [])))
]
]
------------------------------------------------------------------------
]
----------------------------------------------------------------------------
] | 29,003 | main ∷ HasCallStack ⇒ IO ()
main = doMain
------------------------------------------------------------------------------
[ testGroup "HabitOfFate.Server"
------------------------------------------------------------------------------
[ testGroup "JSON API" $
----------------------------------------------------------------------------
let apiTestCase ∷ String → (SessionIO ()) → TestTree
apiTestCase test_name action =
(
createAccount "bitslayer" "password" Testing "localhost"
>=>
(fromMaybe (error "Unable to create account.") >>> runSessionT action)
)
|> serverTestCase test_name
in
------------------------------------------------------------------------
[ testGroup "Missing username/password" $
------------------------------------------------------------------------
let testMissing test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testMissing "Missing username" "create?password=foobar"
, testMissing "Missing password" "create?username=foobar"
]
, testGroup "Log in"
[ testMissing "Missing username" "login?password=foobar"
, testMissing "Missing password" "login?username=foobar"
]
]
------------------------------------------------------------------------
, testGroup "Empty username/password" $
------------------------------------------------------------------------
let testEmpty test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testEmpty "Empty username" "create?username="
, testEmpty "Empty password" "create?password="
]
]
------------------------------------------------------------------------
, apiTestCase "Logging out makes habits forbidden to access." $ do
------------------------------------------------------------------------
logout
try getHabits >>= \case
Left (UnexpectedStatus _ 403) → pure ()
Left e → throwM e
_ → assertFailure "No exception raised."
------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506")
>>=
(@?= Nothing)
------------------------------------------------------------------------
, testGroup "putGroup"
------------------------------------------------------------------------
[ apiTestCase "Putting a group and then fetching it returns the group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroup test_group_id >>= (@?= Just test_group)
--------------------------------------------------------------------
, apiTestCase "Putting a group causes fetching all groups to return a singleton map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroups >>= (@?= [(test_group_id, test_group)])
--------------------------------------------------------------------
, apiTestCase "Putting a group, replacing it, and then fetching all groups returns the replaced group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
replaceGroup test_group_id test_group_2
getGroups >>= (@?= [(test_group_id, test_group_2)])
]
------------------------------------------------------------------------
, testGroup "putHabit"
------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
--------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
replaceHabit test_habit_id test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit_2)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit with missing groups creates habit with no groups" $ do
--------------------------------------------------------------------
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
--------------------------------------------------------------------
, apiTestCase "Putting a habit with existing group returns expected habit" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
]
------------------------------------------------------------------------
, testGroup "deleteGroup"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing group returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteGroup test_group_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a group then deleting it returns ResourceDeleted and causes fetching all groups to return an empty map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getGroups >>= (view items_count_ >>> (@?= 0))
--------------------------------------------------------------------
, apiTestCase "Deleting a group removes it from all habits" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
]
------------------------------------------------------------------------
, testGroup "deleteHabit"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing habit returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteHabit test_habit_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a habit then deleting it returns ResourceDeleted and causes fetching all habits to return an empty map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
deleteHabit test_habit_id >>= (@?= ResourceDeleted)
getHabits >>= (view items_count_ >>> (@?= 0))
]
----------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
----------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
----------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
----------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506") >>= (@?= Nothing)
----------------------------------------------------------------------------
, testGroup "putHabit"
----------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
------------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
------------------------------------------------------------------------
, testGroup "Putting two habits causes them to be returned in order of creation" $
------------------------------------------------------------------------
[ apiTestCase "Test habit 1 followed by test habit 2" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit), (test_habit_id_2, test_habit_2)])
------------------------------------------------------------------------
, apiTestCase "Test habit 2 followed by test habit 1" $ do
------------------------------------------------------------------------
createHabit test_habit_id_2 test_habit_2
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id_2, test_habit_2), (test_habit_id, test_habit)])
]
------------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [FailureResult])
, (test_habit_id_2, [SuccessResult])
, (test_habit_id_2, [])
]
getMarks >>= (@?=
[ Mark FailureResult $ test_habit ^. importance_
, Mark SuccessResult $ test_habit_2 ^. difficulty_
])
------------------------------------------------------------------------
, testCase "Putting a habit causes the accounts to be written" $ do
------------------------------------------------------------------------
accounts_changed_signal ← newTVarIO False
(makeAppRunningInTestMode
<$> newTVarIO mempty
<*> pure accounts_changed_signal
) >>=
flip withApplication (
\port → do
session_info ← fromJust <$> createAccount "bitslayer" "password" Testing "localhost" port
flip runSessionT session_info $ createHabit test_habit_id test_habit
)
atomically (readTVar accounts_changed_signal) >>= (@?= True)
]
----------------------------------------------------------------------------
, testGroup "markHabits"
----------------------------------------------------------------------------
[ apiTestCase "Marking a habit gets the right marks" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [SuccessResult])
, (test_habit_id_2, [FailureResult])
, (test_habit_id, [])
]
getMarks >>= (@?=
[ Mark SuccessResult $ test_habit ^. difficulty_
, Mark FailureResult $ test_habit_2 ^. importance_
])
]
----------------------------------------------------------------------------
, testGroup "configuration"
----------------------------------------------------------------------------
[ apiTestCase "Put then get" $ do
------------------------------------------------------------------------
Configuration old_tzlabel ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
getConfiguration >>= (@?= new_configuration)
------------------------------------------------------------------------
, apiTestCase "Put then reset" $ do
------------------------------------------------------------------------
old_configuration@(Configuration old_tzlabel) ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
resetConfiguration
getConfiguration >>= (@?= old_configuration)
]
----------------------------------------------------------------------------
, testGroup "deadlines"
----------------------------------------------------------------------------
[ apiTestCase "Two habits with neither having any deadlines" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [])
------------------------------------------------------------------------
, apiTestCase "Two habits with one having a Once deadline" $ do
------------------------------------------------------------------------
createHabit test_habit_id (test_habit & frequency_ .~ (Once (Just (dayHour 0 0))))
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, []), (test_habit_id_2, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getMarks
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, [SuccessResult, FailureResult])]
>>= (@?=
[ Mark SuccessResult $ test_habit_2 ^. difficulty_
, Mark SuccessResult $ test_habit ^. difficulty_
])
getDeadlines >>= (@?= [])
getHabit test_habit_id >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "Three habits all having Once deadlines" $ do
------------------------------------------------------------------------
let test_habit_1_once = test_habit_1 & frequency_ .~ (Once (Just (dayHour 0 0)))
test_habit_2_once = test_habit_2 & frequency_ .~ (Once (Just (dayHour 1 1)))
test_habit_3_once = test_habit_3 & frequency_ .~ (Once (Just (dayHour 2 2)))
createHabit test_habit_id_1 test_habit_1_once
createHabit test_habit_id_2 test_habit_2_once
createHabit test_habit_id_3 test_habit_3_once
getDeadlines >>= (@?=
[ (test_habit_id_1, [dayHour 0 0])
, (test_habit_id_2, [dayHour 1 1])
, (test_habit_id_3, [dayHour 2 2])
])
markHabits
[ (test_habit_id_1, [])
, (test_habit_id_2, [FailureResult])
, (test_habit_id_3, [SuccessResult, FailureResult])
]
>>= (@?=
[ Mark FailureResult $ test_habit_2 ^. importance_
, Mark SuccessResult $ test_habit_3 ^. difficulty_
])
getDeadlines >>= (@?= [(test_habit_id_1, [dayHour 0 0])])
getHabit test_habit_id_1 >>= (@?= Just test_habit_1_once)
getHabit test_habit_id_2 >>= (@?= Nothing)
getHabit test_habit_id_3 >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "One habit repeated daily" $ do
------------------------------------------------------------------------
putConfiguration $ Configuration Etc__UTC
createHabit test_habit_id
(test_habit &
frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour 0 0) (Daily 1)
)
LocalTime (ModifiedJulianDay d) _ ← liftIO getCurrentTime <&> utcToLocalTime utc
getDeadlines >>= (@?= [(test_habit_id, [dayHour (d-i) 0 | i ← [0,1,2]])])
markHabits [(test_habit_id, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit ^. difficulty_ ])
getDeadlines >>= (@?= [])
new_test_habit ← getHabit test_habit_id >>= maybe (assertFailure "Habit not found.") pure
new_test_habit @?= (
test_habit
& maybe_last_marked_ .~ new_test_habit ^. maybe_last_marked_
& frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour (fromInteger (d+1)) 0) (Daily 1)
)
last_marked_time ←
maybe
(assertFailure "Habit was not marked.")
pure
(new_test_habit ^. maybe_last_marked_)
current_time ← liftIO getCurrentTime <&> utcToLocalTime utc
assertBool "Current time was before last marked time." (current_time >= last_marked_time)
]
]
----------------------------------------------------------------------------
, testGroup "Web" $
----------------------------------------------------------------------------
[ testGroup "Redirections" $
------------------------------------------------------------------------
[ webTestCase "GET / redirects to /habits" $ do
(response, _) ← requestDocument "/" $ setRequestMethod "GET"
assertRedirectsTo response "/habits"
, webTestCase "GET /habits redirects to /login" $ do
(response, _) ← requestDocument "/habits" $ setRequestMethod "GET"
assertRedirectsTo response "/login"
]
------------------------------------------------------------------------
, testGroup "Login page" $
------------------------------------------------------------------------
[ webTestCase "GET /login returns login page" $ do
(_, tags) ← requestDocument "/login" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Login"
, webTestCase "POST /login for non-existent user returns login page withe error" $ do
(_, tags) ← requestDocument "/login" $
setRequestBodyURLEncoded [("username","username"), ("password","password")]
assertPageTitleEquals tags "Habit of Fate - Login"
assertTextIs tags "error-message" "No account has that username."
]
------------------------------------------------------------------------
, testGroup "Create page" $
------------------------------------------------------------------------
[ webTestCase "GET /create returns account creation page" $ do
(_, tags) ← requestDocument "/create" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Account Creation"
, webTestCase "POST /create with fields filled in redirects to /" $ do
(response, _) ← createTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account causes / to load the habits page" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating an account then logging in redirects to /" $ do
_ ← createTestAccount "username" "password"
(response, _) ← loginTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account makes /habits display the list of habits" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating a conflicting account displays an error message" $ do
_ ← createTestAccount "username" "password"
(response, tags) ← createTestAccount "username" "password"
getResponseStatusCode response @?= 409
assertTextIs tags "error-message" "This account already exists."
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the group edit page for an existing group." $ do
_ ← createTestAccount "username" "password"
createGroupViaWeb test_group_id test_group
(response, tags) ←
requestDocument ([i|/groups/#{UUID.toText test_group_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractGroup tags >>= (@?= test_group)
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the habit edit page for an existing habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_2 test_habit_2
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_2}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_2)
, webTestCase "Open the habit edit page for a once habit with deadline." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_once test_habit_once
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_once}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_once)
, webTestCase "Open the habit edit page for a daily repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_daily
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_daily)
, webTestCase "Open the habit edit page for a weekly repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_weekly
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_weekly)
, webTestCase "Open the habit edit page for a habit with a nontrivial last marked field." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_with_last_marked test_habit_with_last_marked
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_with_last_marked}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_with_last_marked)
, webTestCase "Create a habit with a missing group via. web then open." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_group test_habit_group
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_group}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= (test_habit_group & (group_membership_ .~ [])))
]
]
------------------------------------------------------------------------
]
----------------------------------------------------------------------------
] | 29,003 | main = doMain
------------------------------------------------------------------------------
[ testGroup "HabitOfFate.Server"
------------------------------------------------------------------------------
[ testGroup "JSON API" $
----------------------------------------------------------------------------
let apiTestCase ∷ String → (SessionIO ()) → TestTree
apiTestCase test_name action =
(
createAccount "bitslayer" "password" Testing "localhost"
>=>
(fromMaybe (error "Unable to create account.") >>> runSessionT action)
)
|> serverTestCase test_name
in
------------------------------------------------------------------------
[ testGroup "Missing username/password" $
------------------------------------------------------------------------
let testMissing test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testMissing "Missing username" "create?password=foobar"
, testMissing "Missing password" "create?username=foobar"
]
, testGroup "Log in"
[ testMissing "Missing username" "login?password=foobar"
, testMissing "Missing password" "login?username=foobar"
]
]
------------------------------------------------------------------------
, testGroup "Empty username/password" $
------------------------------------------------------------------------
let testEmpty test_name path =
serverTestCase test_name $ \port → do
response ←
defaultRequest
|> setRequestMethod "POST"
|> setRequestHost "localhost"
|> setRequestPort port
|> setRequestPath ("/api/" ⊕ path)
|> httpNoBody
400 @=? responseStatusCode response
in
[ testGroup "Create account"
[ testEmpty "Empty username" "create?username="
, testEmpty "Empty password" "create?password="
]
]
------------------------------------------------------------------------
, apiTestCase "Logging out makes habits forbidden to access." $ do
------------------------------------------------------------------------
logout
try getHabits >>= \case
Left (UnexpectedStatus _ 403) → pure ()
Left e → throwM e
_ → assertFailure "No exception raised."
------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506")
>>=
(@?= Nothing)
------------------------------------------------------------------------
, testGroup "putGroup"
------------------------------------------------------------------------
[ apiTestCase "Putting a group and then fetching it returns the group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroup test_group_id >>= (@?= Just test_group)
--------------------------------------------------------------------
, apiTestCase "Putting a group causes fetching all groups to return a singleton map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
getGroups >>= (@?= [(test_group_id, test_group)])
--------------------------------------------------------------------
, apiTestCase "Putting a group, replacing it, and then fetching all groups returns the replaced group" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
replaceGroup test_group_id test_group_2
getGroups >>= (@?= [(test_group_id, test_group_2)])
]
------------------------------------------------------------------------
, testGroup "putHabit"
------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
--------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
replaceHabit test_habit_id test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit_2)])
--------------------------------------------------------------------
, apiTestCase "Putting a habit with missing groups creates habit with no groups" $ do
--------------------------------------------------------------------
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
--------------------------------------------------------------------
, apiTestCase "Putting a habit with existing group returns expected habit" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
]
------------------------------------------------------------------------
, testGroup "deleteGroup"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing group returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteGroup test_group_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a group then deleting it returns ResourceDeleted and causes fetching all groups to return an empty map" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getGroups >>= (view items_count_ >>> (@?= 0))
--------------------------------------------------------------------
, apiTestCase "Deleting a group removes it from all habits" $ do
--------------------------------------------------------------------
createGroup test_group_id test_group
createHabit test_habit_id_group test_habit_group
getHabit test_habit_id_group >>= (@?= Just test_habit_group)
deleteGroup test_group_id >>= (@?= ResourceDeleted)
getHabit test_habit_id_group >>= (@?= Just (test_habit_group & group_membership_ .~ []))
]
------------------------------------------------------------------------
, testGroup "deleteHabit"
------------------------------------------------------------------------
[ apiTestCase "Deleting a non-existing habit returns NoResourceToDelete" $ do
--------------------------------------------------------------------
deleteHabit test_habit_id >>= (@?= NoResourceToDelete)
--------------------------------------------------------------------
, apiTestCase "Putting a habit then deleting it returns ResourceDeleted and causes fetching all habits to return an empty map" $ do
--------------------------------------------------------------------
createHabit test_habit_id test_habit
deleteHabit test_habit_id >>= (@?= ResourceDeleted)
getHabits >>= (view items_count_ >>> (@?= 0))
]
----------------------------------------------------------------------------
, apiTestCase "Fetching all habits from a new account returns an empty array" $
----------------------------------------------------------------------------
getHabits >>= (view items_count_ >>> (@?= 0))
----------------------------------------------------------------------------
, apiTestCase "Fetching a habit when none exist returns Nothing" $
----------------------------------------------------------------------------
getHabit (read "730e9d4a-7d72-4a28-a19b-0bcc621c1506") >>= (@?= Nothing)
----------------------------------------------------------------------------
, testGroup "putHabit"
----------------------------------------------------------------------------
[ apiTestCase "Putting a habit and then fetching it returns the habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabit test_habit_id >>= (@?= Just test_habit)
------------------------------------------------------------------------
, apiTestCase "Putting a habit causes fetching all habits to return a singleton map" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id, test_habit)])
------------------------------------------------------------------------
, testGroup "Putting two habits causes them to be returned in order of creation" $
------------------------------------------------------------------------
[ apiTestCase "Test habit 1 followed by test habit 2" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getHabits >>= (@?= [(test_habit_id, test_habit), (test_habit_id_2, test_habit_2)])
------------------------------------------------------------------------
, apiTestCase "Test habit 2 followed by test habit 1" $ do
------------------------------------------------------------------------
createHabit test_habit_id_2 test_habit_2
createHabit test_habit_id test_habit
getHabits >>= (@?= [(test_habit_id_2, test_habit_2), (test_habit_id, test_habit)])
]
------------------------------------------------------------------------
, apiTestCase "Putting a habit, replacing it, and then fetching all habits returns the replaced habit" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [FailureResult])
, (test_habit_id_2, [SuccessResult])
, (test_habit_id_2, [])
]
getMarks >>= (@?=
[ Mark FailureResult $ test_habit ^. importance_
, Mark SuccessResult $ test_habit_2 ^. difficulty_
])
------------------------------------------------------------------------
, testCase "Putting a habit causes the accounts to be written" $ do
------------------------------------------------------------------------
accounts_changed_signal ← newTVarIO False
(makeAppRunningInTestMode
<$> newTVarIO mempty
<*> pure accounts_changed_signal
) >>=
flip withApplication (
\port → do
session_info ← fromJust <$> createAccount "bitslayer" "password" Testing "localhost" port
flip runSessionT session_info $ createHabit test_habit_id test_habit
)
atomically (readTVar accounts_changed_signal) >>= (@?= True)
]
----------------------------------------------------------------------------
, testGroup "markHabits"
----------------------------------------------------------------------------
[ apiTestCase "Marking a habit gets the right marks" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
void $ markHabits
[ (test_habit_id, [SuccessResult])
, (test_habit_id_2, [FailureResult])
, (test_habit_id, [])
]
getMarks >>= (@?=
[ Mark SuccessResult $ test_habit ^. difficulty_
, Mark FailureResult $ test_habit_2 ^. importance_
])
]
----------------------------------------------------------------------------
, testGroup "configuration"
----------------------------------------------------------------------------
[ apiTestCase "Put then get" $ do
------------------------------------------------------------------------
Configuration old_tzlabel ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
getConfiguration >>= (@?= new_configuration)
------------------------------------------------------------------------
, apiTestCase "Put then reset" $ do
------------------------------------------------------------------------
old_configuration@(Configuration old_tzlabel) ← getConfiguration
let new_tzlabel = case old_tzlabel of
Pacific__Pago_Pago → Pacific__Palau
_ → Pacific__Pago_Pago
new_configuration = Configuration new_tzlabel
putConfiguration $ new_configuration
resetConfiguration
getConfiguration >>= (@?= old_configuration)
]
----------------------------------------------------------------------------
, testGroup "deadlines"
----------------------------------------------------------------------------
[ apiTestCase "Two habits with neither having any deadlines" $ do
------------------------------------------------------------------------
createHabit test_habit_id test_habit
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [])
------------------------------------------------------------------------
, apiTestCase "Two habits with one having a Once deadline" $ do
------------------------------------------------------------------------
createHabit test_habit_id (test_habit & frequency_ .~ (Once (Just (dayHour 0 0))))
createHabit test_habit_id_2 test_habit_2
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, []), (test_habit_id_2, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getMarks
>>= (@?= [ Mark SuccessResult $ test_habit_2 ^. difficulty_ ])
getDeadlines >>= (@?= [(test_habit_id, [dayHour 0 0])])
markHabits [(test_habit_id, [SuccessResult, FailureResult])]
>>= (@?=
[ Mark SuccessResult $ test_habit_2 ^. difficulty_
, Mark SuccessResult $ test_habit ^. difficulty_
])
getDeadlines >>= (@?= [])
getHabit test_habit_id >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "Three habits all having Once deadlines" $ do
------------------------------------------------------------------------
let test_habit_1_once = test_habit_1 & frequency_ .~ (Once (Just (dayHour 0 0)))
test_habit_2_once = test_habit_2 & frequency_ .~ (Once (Just (dayHour 1 1)))
test_habit_3_once = test_habit_3 & frequency_ .~ (Once (Just (dayHour 2 2)))
createHabit test_habit_id_1 test_habit_1_once
createHabit test_habit_id_2 test_habit_2_once
createHabit test_habit_id_3 test_habit_3_once
getDeadlines >>= (@?=
[ (test_habit_id_1, [dayHour 0 0])
, (test_habit_id_2, [dayHour 1 1])
, (test_habit_id_3, [dayHour 2 2])
])
markHabits
[ (test_habit_id_1, [])
, (test_habit_id_2, [FailureResult])
, (test_habit_id_3, [SuccessResult, FailureResult])
]
>>= (@?=
[ Mark FailureResult $ test_habit_2 ^. importance_
, Mark SuccessResult $ test_habit_3 ^. difficulty_
])
getDeadlines >>= (@?= [(test_habit_id_1, [dayHour 0 0])])
getHabit test_habit_id_1 >>= (@?= Just test_habit_1_once)
getHabit test_habit_id_2 >>= (@?= Nothing)
getHabit test_habit_id_3 >>= (@?= Nothing)
------------------------------------------------------------------------
, apiTestCase "One habit repeated daily" $ do
------------------------------------------------------------------------
putConfiguration $ Configuration Etc__UTC
createHabit test_habit_id
(test_habit &
frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour 0 0) (Daily 1)
)
LocalTime (ModifiedJulianDay d) _ ← liftIO getCurrentTime <&> utcToLocalTime utc
getDeadlines >>= (@?= [(test_habit_id, [dayHour (d-i) 0 | i ← [0,1,2]])])
markHabits [(test_habit_id, [SuccessResult])]
>>= (@?= [ Mark SuccessResult $ test_habit ^. difficulty_ ])
getDeadlines >>= (@?= [])
new_test_habit ← getHabit test_habit_id >>= maybe (assertFailure "Habit not found.") pure
new_test_habit @?= (
test_habit
& maybe_last_marked_ .~ new_test_habit ^. maybe_last_marked_
& frequency_ .~ Repeated (KeepNumberOfDays 3) (dayHour (fromInteger (d+1)) 0) (Daily 1)
)
last_marked_time ←
maybe
(assertFailure "Habit was not marked.")
pure
(new_test_habit ^. maybe_last_marked_)
current_time ← liftIO getCurrentTime <&> utcToLocalTime utc
assertBool "Current time was before last marked time." (current_time >= last_marked_time)
]
]
----------------------------------------------------------------------------
, testGroup "Web" $
----------------------------------------------------------------------------
[ testGroup "Redirections" $
------------------------------------------------------------------------
[ webTestCase "GET / redirects to /habits" $ do
(response, _) ← requestDocument "/" $ setRequestMethod "GET"
assertRedirectsTo response "/habits"
, webTestCase "GET /habits redirects to /login" $ do
(response, _) ← requestDocument "/habits" $ setRequestMethod "GET"
assertRedirectsTo response "/login"
]
------------------------------------------------------------------------
, testGroup "Login page" $
------------------------------------------------------------------------
[ webTestCase "GET /login returns login page" $ do
(_, tags) ← requestDocument "/login" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Login"
, webTestCase "POST /login for non-existent user returns login page withe error" $ do
(_, tags) ← requestDocument "/login" $
setRequestBodyURLEncoded [("username","username"), ("password","password")]
assertPageTitleEquals tags "Habit of Fate - Login"
assertTextIs tags "error-message" "No account has that username."
]
------------------------------------------------------------------------
, testGroup "Create page" $
------------------------------------------------------------------------
[ webTestCase "GET /create returns account creation page" $ do
(_, tags) ← requestDocument "/create" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - Account Creation"
, webTestCase "POST /create with fields filled in redirects to /" $ do
(response, _) ← createTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account causes / to load the habits page" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating an account then logging in redirects to /" $ do
_ ← createTestAccount "username" "password"
(response, _) ← loginTestAccount "username" "password"
assertRedirectsTo response "/"
, webTestCase "Creating an account makes /habits display the list of habits" $ do
_ ← createTestAccount "username" "password"
(_, tags) ← requestDocument "/habits" $ setRequestMethod "GET"
assertPageTitleEquals tags "Habit of Fate - List of Habits"
, webTestCase "Creating a conflicting account displays an error message" $ do
_ ← createTestAccount "username" "password"
(response, tags) ← createTestAccount "username" "password"
getResponseStatusCode response @?= 409
assertTextIs tags "error-message" "This account already exists."
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the group edit page for an existing group." $ do
_ ← createTestAccount "username" "password"
createGroupViaWeb test_group_id test_group
(response, tags) ←
requestDocument ([i|/groups/#{UUID.toText test_group_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractGroup tags >>= (@?= test_group)
]
------------------------------------------------------------------------
, testGroup "Habits" $
------------------------------------------------------------------------
[ webTestCase "Open the habit edit page for an existing habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_2 test_habit_2
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_2}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_2)
, webTestCase "Open the habit edit page for a once habit with deadline." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_once test_habit_once
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_once}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_once)
, webTestCase "Open the habit edit page for a daily repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_daily
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_daily)
, webTestCase "Open the habit edit page for a weekly repeated habit." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id test_habit_weekly
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_weekly)
, webTestCase "Open the habit edit page for a habit with a nontrivial last marked field." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_with_last_marked test_habit_with_last_marked
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_with_last_marked}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= test_habit_with_last_marked)
, webTestCase "Create a habit with a missing group via. web then open." $ do
_ ← createTestAccount "username" "password"
createHabitViaWeb test_habit_id_group test_habit_group
(response, tags) ←
requestDocument ([i|/habits/#{UUID.toText test_habit_id_group}|] |> pack |> encodeUtf8) $
setRequestMethod "GET"
responseStatus response @?= ok200
extractHabit tags >>= (@?= (test_habit_group & (group_membership_ .~ [])))
]
]
------------------------------------------------------------------------
]
----------------------------------------------------------------------------
] | 28,975 | false | true | 0 | 27 | 8,715 | 4,184 | 2,114 | 2,070 | null | null |
drbean/pdrt-sandbox | src/Data/DRS/LambdaCalculus.hs | apache-2.0 | renameCons (Merge _ _) _ _ = [] | 34 | renameCons (Merge _ _) _ _ = [] | 34 | renameCons (Merge _ _) _ _ = [] | 34 | false | false | 0 | 7 | 10 | 23 | 11 | 12 | null | null |
MichielDerhaeg/stack | src/Stack/Types/Config.hs | bsd-3-clause | readColorWhen :: ReadM ColorWhen
readColorWhen = do
s <- OA.readerAsk
case s of
"never" -> return ColorNever
"always" -> return ColorAlways
"auto" -> return ColorAuto
_ -> OA.readerError "Expected values of color option are 'never', 'always', or 'auto'."
-- | A superset of 'Config' adding information on how to build code. The reason
-- for this breakdown is because we will need some of the information from
-- 'Config' in order to determine the values here.
--
-- These are the components which know nothing about local configuration. | 578 | readColorWhen :: ReadM ColorWhen
readColorWhen = do
s <- OA.readerAsk
case s of
"never" -> return ColorNever
"always" -> return ColorAlways
"auto" -> return ColorAuto
_ -> OA.readerError "Expected values of color option are 'never', 'always', or 'auto'."
-- | A superset of 'Config' adding information on how to build code. The reason
-- for this breakdown is because we will need some of the information from
-- 'Config' in order to determine the values here.
--
-- These are the components which know nothing about local configuration. | 578 | readColorWhen = do
s <- OA.readerAsk
case s of
"never" -> return ColorNever
"always" -> return ColorAlways
"auto" -> return ColorAuto
_ -> OA.readerError "Expected values of color option are 'never', 'always', or 'auto'."
-- | A superset of 'Config' adding information on how to build code. The reason
-- for this breakdown is because we will need some of the information from
-- 'Config' in order to determine the values here.
--
-- These are the components which know nothing about local configuration. | 545 | false | true | 0 | 12 | 128 | 79 | 37 | 42 | null | null |
schernichkin/snakes | src/Data/Snakes.hs | bsd-3-clause | diffStream :: (Stream s m t, Eq t, Num a, Ord a)
=> SnakeShape -> Maybe a -> s -> s -> m (Maybe (DiffStream s t a))
diffStream sh d l r = fmap (snakeToDiffStream sh l r) <$> snake d l r | 198 | diffStream :: (Stream s m t, Eq t, Num a, Ord a)
=> SnakeShape -> Maybe a -> s -> s -> m (Maybe (DiffStream s t a))
diffStream sh d l r = fmap (snakeToDiffStream sh l r) <$> snake d l r | 197 | diffStream sh d l r = fmap (snakeToDiffStream sh l r) <$> snake d l r | 69 | false | true | 0 | 14 | 56 | 113 | 55 | 58 | null | null |
Daniel-Diaz/rachel | Rachel/Compilation.hs | bsd-3-clause | isDecHead :: String -> Bool
isDecHead str = not (null str) && (isAlpha (head str) || head str == '(' || head str == '#') | 120 | isDecHead :: String -> Bool
isDecHead str = not (null str) && (isAlpha (head str) || head str == '(' || head str == '#') | 120 | isDecHead str = not (null str) && (isAlpha (head str) || head str == '(' || head str == '#') | 92 | false | true | 2 | 13 | 24 | 72 | 32 | 40 | null | null |
ancientlanguage/haskell-analysis | grammar/src/Grammar/Common/Decompose.hs | mit | decomposeChar '\xF981' = "\x5973" | 33 | decomposeChar '\xF981' = "\x5973" | 33 | decomposeChar '\xF981' = "\x5973" | 33 | false | false | 0 | 5 | 3 | 9 | 4 | 5 | null | null |
PuZZleDucK/Hls | Hbasename.hs | gpl-3.0 | startsWith [] _ = False | 23 | startsWith [] _ = False | 23 | startsWith [] _ = False | 23 | false | false | 0 | 5 | 4 | 15 | 6 | 9 | null | null |
gcampax/ghc | compiler/typecheck/TcGenDeriv.hs | bsd-3-clause | true_Expr = nlHsVar true_RDR | 34 | true_Expr = nlHsVar true_RDR | 34 | true_Expr = nlHsVar true_RDR | 34 | false | false | 1 | 5 | 9 | 12 | 4 | 8 | null | null |
alekar/hugs | packages/Cabal/Network/Hackage/CabalInstall/TarUtils.hs | bsd-3-clause | locateFile :: [FilePath] -- ^File list.
-> FilePath -- ^Base directory.
-> [FilePath] -- ^List of filenames to locate.
-> Maybe FilePath
locateFile files dir names
= find findFile files
where findFile file
= let (root,name) = splitFileName file
in root == dir && name `elem` names
{-|
Locate all files with a given extension and return the shortest result.
@
locateFileExt [\"somedir\/test.cabal\"] \"cabal\"
=> Just \"somedir\/test.cabal\"
@
-} | 527 | locateFile :: [FilePath] -- ^File list.
-> FilePath -- ^Base directory.
-> [FilePath] -- ^List of filenames to locate.
-> Maybe FilePath
locateFile files dir names
= find findFile files
where findFile file
= let (root,name) = splitFileName file
in root == dir && name `elem` names
{-|
Locate all files with a given extension and return the shortest result.
@
locateFileExt [\"somedir\/test.cabal\"] \"cabal\"
=> Just \"somedir\/test.cabal\"
@
-} | 527 | locateFile files dir names
= find findFile files
where findFile file
= let (root,name) = splitFileName file
in root == dir && name `elem` names
{-|
Locate all files with a given extension and return the shortest result.
@
locateFileExt [\"somedir\/test.cabal\"] \"cabal\"
=> Just \"somedir\/test.cabal\"
@
-} | 355 | false | true | 0 | 11 | 150 | 93 | 49 | 44 | null | null |
urbit/urbit | pkg/hs/urbit-king/lib/Urbit/Vere/Dawn.hs | mit | dawnSendHTTP :: String -> L.ByteString -> RIO e (Either Int L.ByteString)
dawnSendHTTP endpoint requestData = liftIO do
manager <- C.newManager TLS.tlsManagerSettings
initialRequest <- C.parseRequest endpoint
let request = initialRequest
{ C.method = "POST"
, C.requestBody = C.RequestBodyLBS $ requestData
, C.requestHeaders = [("Accept", "application/json"),
("Content-Type", "application/json"),
("Charsets", "utf-8")]
}
response <- C.httpLbs request manager
-- Return body if 200.
let code = HT.statusCode $ C.responseStatus response
case code of
200 -> pure $ Right $ C.responseBody response
_ -> pure $ Left code | 737 | dawnSendHTTP :: String -> L.ByteString -> RIO e (Either Int L.ByteString)
dawnSendHTTP endpoint requestData = liftIO do
manager <- C.newManager TLS.tlsManagerSettings
initialRequest <- C.parseRequest endpoint
let request = initialRequest
{ C.method = "POST"
, C.requestBody = C.RequestBodyLBS $ requestData
, C.requestHeaders = [("Accept", "application/json"),
("Content-Type", "application/json"),
("Charsets", "utf-8")]
}
response <- C.httpLbs request manager
-- Return body if 200.
let code = HT.statusCode $ C.responseStatus response
case code of
200 -> pure $ Right $ C.responseBody response
_ -> pure $ Left code | 737 | dawnSendHTTP endpoint requestData = liftIO do
manager <- C.newManager TLS.tlsManagerSettings
initialRequest <- C.parseRequest endpoint
let request = initialRequest
{ C.method = "POST"
, C.requestBody = C.RequestBodyLBS $ requestData
, C.requestHeaders = [("Accept", "application/json"),
("Content-Type", "application/json"),
("Charsets", "utf-8")]
}
response <- C.httpLbs request manager
-- Return body if 200.
let code = HT.statusCode $ C.responseStatus response
case code of
200 -> pure $ Right $ C.responseBody response
_ -> pure $ Left code | 663 | false | true | 1 | 14 | 201 | 212 | 107 | 105 | null | null |
brendanhay/gogol | gogol-resourcemanager/gen/Network/Google/Resource/CloudResourceManager/Projects/Patch.hs | mpl-2.0 | -- | Multipart request metadata.
ppPayload :: Lens' ProjectsPatch Project
ppPayload
= lens _ppPayload (\ s a -> s{_ppPayload = a}) | 132 | ppPayload :: Lens' ProjectsPatch Project
ppPayload
= lens _ppPayload (\ s a -> s{_ppPayload = a}) | 99 | ppPayload
= lens _ppPayload (\ s a -> s{_ppPayload = a}) | 58 | true | true | 1 | 9 | 22 | 44 | 22 | 22 | null | null |
mhwombat/creatur-wains-iomha | src/ALife/Creatur/Wain/Iomha/Experiment.hs | bsd-3-clause | updateChildren :: StateT Experiment IO ()
updateChildren = do
(a:matureChildren) <- W.weanMatureChildren <$> use subject
assign subject a
(a':deadChildren) <- W.pruneDeadChildren <$> use subject
assign subject a'
assign weanlings (matureChildren ++ deadChildren)
(summary.rWeanCount) += length matureChildren | 320 | updateChildren :: StateT Experiment IO ()
updateChildren = do
(a:matureChildren) <- W.weanMatureChildren <$> use subject
assign subject a
(a':deadChildren) <- W.pruneDeadChildren <$> use subject
assign subject a'
assign weanlings (matureChildren ++ deadChildren)
(summary.rWeanCount) += length matureChildren | 320 | updateChildren = do
(a:matureChildren) <- W.weanMatureChildren <$> use subject
assign subject a
(a':deadChildren) <- W.pruneDeadChildren <$> use subject
assign subject a'
assign weanlings (matureChildren ++ deadChildren)
(summary.rWeanCount) += length matureChildren | 278 | false | true | 0 | 9 | 47 | 112 | 52 | 60 | null | null |
mjhopkins/StopPayingForFreeMonads | Expressions.hs | mit | projR :: (f :+: g) a -> Maybe (g a)
projR s = case s of
Inl _ -> Nothing
Inr ga -> Just ga
-- Fix | 103 | projR :: (f :+: g) a -> Maybe (g a)
projR s = case s of
Inl _ -> Nothing
Inr ga -> Just ga
-- Fix | 103 | projR s = case s of
Inl _ -> Nothing
Inr ga -> Just ga
-- Fix | 67 | false | true | 0 | 8 | 32 | 63 | 30 | 33 | null | null |
perryleo/sicp | ch1/sicpc1e28.hs | mit | -- To implement Miller-Rabin test, we need a procedure that computes the
-- exponential of a number modulo another number
expmod :: (Integral a) => a -> a -> a -> a
expmod base 0 m = 1 | 184 | expmod :: (Integral a) => a -> a -> a -> a
expmod base 0 m = 1 | 62 | expmod base 0 m = 1 | 19 | true | true | 0 | 10 | 37 | 47 | 23 | 24 | null | null |
avieth/diplomacy | Data/AtLeast.hs | bsd-3-clause | fromList :: [t] -> AtLeast Z t
fromList xs = AtLeast VNil xs | 60 | fromList :: [t] -> AtLeast Z t
fromList xs = AtLeast VNil xs | 60 | fromList xs = AtLeast VNil xs | 29 | false | true | 0 | 6 | 12 | 31 | 15 | 16 | null | null |
Mathnerd314/lamdu | src/Lamdu/CodeEdit/Sugar/Monad.hs | gpl-3.0 | convertSubexpression :: (MonadA m, Monoid a) => ExprMM m a -> SugarM m (ExpressionU m a)
convertSubexpression exprI = do
convertSub <- scConvertSubexpression <$> readContext
convertSub exprI | 194 | convertSubexpression :: (MonadA m, Monoid a) => ExprMM m a -> SugarM m (ExpressionU m a)
convertSubexpression exprI = do
convertSub <- scConvertSubexpression <$> readContext
convertSub exprI | 194 | convertSubexpression exprI = do
convertSub <- scConvertSubexpression <$> readContext
convertSub exprI | 105 | false | true | 0 | 9 | 30 | 68 | 32 | 36 | null | null |
phaazon/OpenGLRaw | src/Graphics/Rendering/OpenGL/Raw/Tokens.hs | bsd-3-clause | gl_PIXEL_MAP_B_TO_B :: GLenum
gl_PIXEL_MAP_B_TO_B = 0x0C78 | 58 | gl_PIXEL_MAP_B_TO_B :: GLenum
gl_PIXEL_MAP_B_TO_B = 0x0C78 | 58 | gl_PIXEL_MAP_B_TO_B = 0x0C78 | 28 | false | true | 0 | 4 | 5 | 11 | 6 | 5 | null | null |
rueshyna/gogol | gogol-oauth2/gen/Network/Google/OAuth2/Types.hs | mpl-2.0 | -- | Know the list of people in your circles, your age range, and language
plusLoginScope :: Proxy '["https://www.googleapis.com/auth/plus.login"]
plusLoginScope = Proxy | 169 | plusLoginScope :: Proxy '["https://www.googleapis.com/auth/plus.login"]
plusLoginScope = Proxy | 94 | plusLoginScope = Proxy | 22 | true | true | 0 | 7 | 21 | 20 | 11 | 9 | null | null |
brendanhay/gogol | gogol-dfareporting/gen/Network/Google/DFAReporting/Types/Product.hs | mpl-2.0 | -- | Name of this placement strategy. This is a required field. It must be
-- less than 256 characters long and unique among placement strategies of
-- the same account.
psName :: Lens' PlacementStrategy (Maybe Text)
psName = lens _psName (\ s a -> s{_psName = a}) | 264 | psName :: Lens' PlacementStrategy (Maybe Text)
psName = lens _psName (\ s a -> s{_psName = a}) | 94 | psName = lens _psName (\ s a -> s{_psName = a}) | 47 | true | true | 1 | 9 | 47 | 54 | 27 | 27 | null | null |
kaoskorobase/mescaline | resources/hugs/packages/base/Data/IntMap.hs | gpl-3.0 | intersectionWithKey f t1 (Tip k y)
= case lookup k t1 of
Just x -> Tip k (f k x y)
Nothing -> Nil | 113 | intersectionWithKey f t1 (Tip k y)
= case lookup k t1 of
Just x -> Tip k (f k x y)
Nothing -> Nil | 113 | intersectionWithKey f t1 (Tip k y)
= case lookup k t1 of
Just x -> Tip k (f k x y)
Nothing -> Nil | 113 | false | false | 4 | 8 | 39 | 59 | 28 | 31 | null | null |
sof/hdirect | src/CustomAttributes.hs | bsd-3-clause | tyArgsAttr :: Name
tyArgsAttr = "ty_args" | 49 | tyArgsAttr :: Name
tyArgsAttr = "ty_args" | 49 | tyArgsAttr = "ty_args" | 26 | false | true | 0 | 4 | 13 | 11 | 6 | 5 | null | null |
ssaavedra/liquidhaskell | benchmarks/vector-0.10.0.1/Data/Vector.hs | bsd-3-clause | unsafeUpd = G.unsafeUpd | 23 | unsafeUpd = G.unsafeUpd | 23 | unsafeUpd = G.unsafeUpd | 23 | false | false | 0 | 5 | 2 | 8 | 4 | 4 | null | null |
ghcjs/ghcjs | src/Gen2/Compactor.hs | mit | -- do not deduplicate thunks
ignoreStatic :: StaticInfo -> Bool
ignoreStatic (StaticInfo _ StaticThunk {} _) = True | 115 | ignoreStatic :: StaticInfo -> Bool
ignoreStatic (StaticInfo _ StaticThunk {} _) = True | 86 | ignoreStatic (StaticInfo _ StaticThunk {} _) = True | 51 | true | true | 0 | 8 | 17 | 33 | 17 | 16 | null | null |
keithodulaigh/Hets | HasCASL/Sublogic.hs | gpl-2.0 | sl_opInfo :: OpInfo -> Sublogic
sl_opInfo o = comp_list $ sl_typeScheme (opType o) : sl_opDefn (opDefn o)
: map sl_opAttr (Set.toList $ opAttrs o) | 160 | sl_opInfo :: OpInfo -> Sublogic
sl_opInfo o = comp_list $ sl_typeScheme (opType o) : sl_opDefn (opDefn o)
: map sl_opAttr (Set.toList $ opAttrs o) | 160 | sl_opInfo o = comp_list $ sl_typeScheme (opType o) : sl_opDefn (opDefn o)
: map sl_opAttr (Set.toList $ opAttrs o) | 128 | false | true | 0 | 10 | 37 | 65 | 31 | 34 | null | null |
Happy0/haskellscrabble | src/Wordify/Rules/Dictionary.hs | gpl-3.0 | upperCaseWords :: [String] -> [String]
upperCaseWords = (map . map) toUpper | 77 | upperCaseWords :: [String] -> [String]
upperCaseWords = (map . map) toUpper | 75 | upperCaseWords = (map . map) toUpper | 36 | false | true | 0 | 8 | 12 | 37 | 18 | 19 | null | null |
leroux/packages-haskeline | System/Console/Haskeline/Command.hs | bsd-2-clause | setState :: (Monad m, LineState s) => Command m s s
setState s = effect (lineChange s) >> return s | 98 | setState :: (Monad m, LineState s) => Command m s s
setState s = effect (lineChange s) >> return s | 98 | setState s = effect (lineChange s) >> return s | 46 | false | true | 0 | 8 | 19 | 52 | 25 | 27 | null | null |
fabianbergmark/ECMA-262 | src/Language/JavaScript/Host/Console.hs | bsd-2-clause | consoleLogCallImpl :: (Functor m, Monad m, MonadIO m) => InternalCallType m
consoleLogCallImpl f this (List args) = do
forM (intersperse (r.r.r.r.inj $ " ") args) $ \v -> toString v >>= liftIO . putStr
liftIO $ putStrLn ""
return . r.r.r.inj $ Undefined | 259 | consoleLogCallImpl :: (Functor m, Monad m, MonadIO m) => InternalCallType m
consoleLogCallImpl f this (List args) = do
forM (intersperse (r.r.r.r.inj $ " ") args) $ \v -> toString v >>= liftIO . putStr
liftIO $ putStrLn ""
return . r.r.r.inj $ Undefined | 259 | consoleLogCallImpl f this (List args) = do
forM (intersperse (r.r.r.r.inj $ " ") args) $ \v -> toString v >>= liftIO . putStr
liftIO $ putStrLn ""
return . r.r.r.inj $ Undefined | 183 | false | true | 0 | 16 | 48 | 124 | 60 | 64 | null | null |
yanatan16/haskell-chp-wc | src/Data/WordCount/Types.hs | mit | summarize :: Counts -> IO ()
summarize = flip printCounts "total" | 65 | summarize :: Counts -> IO ()
summarize = flip printCounts "total" | 65 | summarize = flip printCounts "total" | 36 | false | true | 0 | 7 | 10 | 25 | 12 | 13 | null | null |
nicoan/miniLogo | src/Evaluation.hs | gpl-3.0 | evalColor (Left Yellow) _ = return (rgb 255 255 0) | 50 | evalColor (Left Yellow) _ = return (rgb 255 255 0) | 50 | evalColor (Left Yellow) _ = return (rgb 255 255 0) | 50 | false | false | 0 | 7 | 9 | 32 | 14 | 18 | null | null |
Numberartificial/workflow | snipets/src/Craft/Chapter18.hs | mit | -- Programming with monads
-- ^^^^^^^^^^^^^^^^^^^^^^^
-- The basics of input/output
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^
-- Reading input is done by getLine and getChar: see Prelude for details.
-- getLine :: IO String
-- getChar :: IO Char
-- Text strings are written using
--
-- putStr :: String -> IO ()
-- putStrLn :: String -> IO ()
-- A hello, world program
helloWorld :: IO ()
helloWorld = putStr "Hello, World!" | 426 | helloWorld :: IO ()
helloWorld = putStr "Hello, World!" | 55 | helloWorld = putStr "Hello, World!" | 35 | true | true | 0 | 7 | 84 | 37 | 22 | 15 | null | null |
BurntSushi/fex | Development/FexA/Experiment.hs | unlicense | -- | Just like `evalIO`, except it stops the program and outputs an error
-- message if one occurs.
evalIO' :: Fex -> IO Value
evalIO' e = evalIO e >>= \e' ->
case e' of
Left err -> putStrLn err >> exitFailure
Right v -> return v
-- | Completely evaluate a Fex term to a value after checking if the static
-- dependencies of the given term exist. If not, then an error message is
-- returned detailing each missing dependency. | 474 | evalIO' :: Fex -> IO Value
evalIO' e = evalIO e >>= \e' ->
case e' of
Left err -> putStrLn err >> exitFailure
Right v -> return v
-- | Completely evaluate a Fex term to a value after checking if the static
-- dependencies of the given term exist. If not, then an error message is
-- returned detailing each missing dependency. | 374 | evalIO' e = evalIO e >>= \e' ->
case e' of
Left err -> putStrLn err >> exitFailure
Right v -> return v
-- | Completely evaluate a Fex term to a value after checking if the static
-- dependencies of the given term exist. If not, then an error message is
-- returned detailing each missing dependency. | 347 | true | true | 0 | 11 | 130 | 70 | 35 | 35 | null | null |
leshchevds/ganeti | src/Ganeti/BasicTypes.hs | bsd-2-clause | -- | Converts a monadic result with a 'String' message into
-- a 'ResultT' with an arbitrary 'Error'.
--
-- Expects that the given action has already taken care of any possible
-- errors. In particular, if applied on @IO (Result a)@, any exceptions
-- should be handled by the given action.
--
-- See also 'toErrorStr'.
mkResultT :: (Monad m, FromString e) => m (Result a) -> ResultT e m a
mkResultT = ResultT . liftM toErrorStr | 428 | mkResultT :: (Monad m, FromString e) => m (Result a) -> ResultT e m a
mkResultT = ResultT . liftM toErrorStr | 108 | mkResultT = ResultT . liftM toErrorStr | 38 | true | true | 1 | 10 | 77 | 67 | 35 | 32 | null | null |
google/codeworld | codeworld-base/src/Extras/Util.hs | apache-2.0 | foreach :: ([input], input -> output) -> [output]
foreach (l, f) = P.map f l | 76 | foreach :: ([input], input -> output) -> [output]
foreach (l, f) = P.map f l | 76 | foreach (l, f) = P.map f l | 26 | false | true | 0 | 7 | 14 | 51 | 27 | 24 | null | null |
phaazon/OpenGLRaw | src/Graphics/Rendering/OpenGL/Raw/Tokens.hs | bsd-3-clause | gl_QUERY_RESULT_ARB :: GLenum
gl_QUERY_RESULT_ARB = 0x8866 | 58 | gl_QUERY_RESULT_ARB :: GLenum
gl_QUERY_RESULT_ARB = 0x8866 | 58 | gl_QUERY_RESULT_ARB = 0x8866 | 28 | false | true | 0 | 4 | 5 | 11 | 6 | 5 | null | null |
fffej/HS-Poker | LookupPatternMatch.hs | bsd-3-clause | getValueFromProduct 440781 = 4518 | 33 | getValueFromProduct 440781 = 4518 | 33 | getValueFromProduct 440781 = 4518 | 33 | false | false | 0 | 5 | 3 | 9 | 4 | 5 | null | null |
haroldcarr/learn-haskell-coq-ml-etc | haskell/playpen/conal-elliot/2019-03-conal-elliott-convolution/src/Lib.hs | unlicense | toEndo :: Monoid a => a -> Endo a
toEndo a = Endo (\z -> a <> z ) | 74 | toEndo :: Monoid a => a -> Endo a
toEndo a = Endo (\z -> a <> z ) | 74 | toEndo a = Endo (\z -> a <> z ) | 40 | false | true | 0 | 8 | 27 | 46 | 22 | 24 | null | null |
laughedelic/sparse-lin-alg | Tests/Matrix.hs | bsd-3-clause | --------------------------------------------------------------------------------
-- LOOKUP/UPDATE --
-------------------
testgr_lookup_update = testGroup "LOOKUP/UPDATE"
[ testProperty "Insert/Erase" prop_ins ] | 215 | testgr_lookup_update = testGroup "LOOKUP/UPDATE"
[ testProperty "Insert/Erase" prop_ins ] | 93 | testgr_lookup_update = testGroup "LOOKUP/UPDATE"
[ testProperty "Insert/Erase" prop_ins ] | 93 | true | false | 0 | 6 | 18 | 23 | 12 | 11 | null | null |
fpco/statistics | Statistics/Distribution/StudentT.hs | bsd-2-clause | logDensityUnscaled :: StudentT -> Double -> Double
logDensityUnscaled (StudentT ndf) x =
log (ndf / (ndf + x*x)) * (0.5 * (1 + ndf)) - logBeta 0.5 (0.5 * ndf) | 162 | logDensityUnscaled :: StudentT -> Double -> Double
logDensityUnscaled (StudentT ndf) x =
log (ndf / (ndf + x*x)) * (0.5 * (1 + ndf)) - logBeta 0.5 (0.5 * ndf) | 162 | logDensityUnscaled (StudentT ndf) x =
log (ndf / (ndf + x*x)) * (0.5 * (1 + ndf)) - logBeta 0.5 (0.5 * ndf) | 111 | false | true | 0 | 12 | 33 | 85 | 44 | 41 | null | null |
meditans/logicExperiments | src/RestrictedSequentCalculus.hs | bsd-3-clause | isUnexaminedTree _ = False | 48 | isUnexaminedTree _ = False | 48 | isUnexaminedTree _ = False | 48 | false | false | 0 | 5 | 25 | 9 | 4 | 5 | null | null |
takayuki/natume | Re.hs | gpl-2.0 | literal :: Parser Char
literal (_,_ ,[]) = syntaxerror | 54 | literal :: Parser Char
literal (_,_ ,[]) = syntaxerror | 54 | literal (_,_ ,[]) = syntaxerror | 31 | false | true | 0 | 7 | 8 | 28 | 15 | 13 | null | null |
infotroph/pandoc | src/Text/Pandoc/Writers/OpenDocument.hs | gpl-2.0 | addTableStyle :: Doc -> State WriterState ()
addTableStyle i = modify $ \s -> s { stTableStyles = i : stTableStyles s } | 119 | addTableStyle :: Doc -> State WriterState ()
addTableStyle i = modify $ \s -> s { stTableStyles = i : stTableStyles s } | 119 | addTableStyle i = modify $ \s -> s { stTableStyles = i : stTableStyles s } | 74 | false | true | 2 | 10 | 22 | 55 | 26 | 29 | null | null |
rjeli/luatalk | src/Lexer.hs | bsd-3-clause | ppToken (Symbol s) = s | 29 | ppToken (Symbol s) = s | 29 | ppToken (Symbol s) = s | 29 | false | false | 0 | 7 | 11 | 15 | 7 | 8 | null | null |
robeverest/accelerate-fft | Data/Array/Accelerate/Math/FFT.hs | bsd-3-clause | isPow2 :: Int -> Bool
isPow2 x = x .&. (x-1) == 0 | 49 | isPow2 :: Int -> Bool
isPow2 x = x .&. (x-1) == 0 | 49 | isPow2 x = x .&. (x-1) == 0 | 27 | false | true | 0 | 8 | 12 | 33 | 17 | 16 | null | null |
urbanslug/ghc | testsuite/tests/partial-sigs/should_compile/ExtraConstraints3.hs | bsd-3-clause | last :: _ => _
last = P.last | 28 | last :: _ => _
last = P.last | 28 | last = P.last | 13 | false | true | 0 | 7 | 7 | 25 | 10 | 15 | null | null |
mhwombat/creatur-wains-iomha | test/SOMTest.hs | bsd-3-clause | main :: IO ()
main = do
files <- map (dir ++) . take 100 . drop 2 <$> getDirectoryContents dir
imgs <- mapM readImage files
som <- evalRandIO makeClassifier
let som' = foldl' update som imgs
let ss = mkSizeSpec2D (Just 500) Nothing
let diagram = drawClassifier . toList $ som' :: QDiagram SVG V2 Double Any
renderSVG "SOMTest.svg" ss diagram | 355 | main :: IO ()
main = do
files <- map (dir ++) . take 100 . drop 2 <$> getDirectoryContents dir
imgs <- mapM readImage files
som <- evalRandIO makeClassifier
let som' = foldl' update som imgs
let ss = mkSizeSpec2D (Just 500) Nothing
let diagram = drawClassifier . toList $ som' :: QDiagram SVG V2 Double Any
renderSVG "SOMTest.svg" ss diagram | 355 | main = do
files <- map (dir ++) . take 100 . drop 2 <$> getDirectoryContents dir
imgs <- mapM readImage files
som <- evalRandIO makeClassifier
let som' = foldl' update som imgs
let ss = mkSizeSpec2D (Just 500) Nothing
let diagram = drawClassifier . toList $ som' :: QDiagram SVG V2 Double Any
renderSVG "SOMTest.svg" ss diagram | 341 | false | true | 1 | 11 | 75 | 141 | 67 | 74 | null | null |
diku-dk/futhark | src/Language/Futhark/TypeChecker/Terms/Monad.hs | isc | initialTermScope :: TermScope
initialTermScope =
TermScope
{ scopeVtable = initialVtable,
scopeTypeTable = mempty,
scopeNameMap = topLevelNameMap,
scopeModTable = mempty
}
where
initialVtable = M.fromList $ mapMaybe addIntrinsicF $ M.toList intrinsics
prim = Scalar . Prim
arrow x y = Scalar $ Arrow mempty Unnamed x y
addIntrinsicF (name, IntrinsicMonoFun pts t) =
Just (name, BoundV Global [] $ arrow pts' $ RetType [] $ prim t)
where
pts' = case pts of
[pt] -> prim pt
_ -> Scalar $ tupleRecord $ map prim pts
addIntrinsicF (name, IntrinsicOverloadedFun ts pts rts) =
Just (name, OverloadedF ts pts rts)
addIntrinsicF (name, IntrinsicPolyFun tvs pts rt) =
Just
( name,
BoundV Global tvs $
fromStruct $ Scalar $ Arrow mempty Unnamed pts' rt
)
where
pts' = case pts of
[pt] -> pt
_ -> Scalar $ tupleRecord pts
addIntrinsicF (name, IntrinsicEquality) =
Just (name, EqualityF)
addIntrinsicF _ = Nothing | 1,095 | initialTermScope :: TermScope
initialTermScope =
TermScope
{ scopeVtable = initialVtable,
scopeTypeTable = mempty,
scopeNameMap = topLevelNameMap,
scopeModTable = mempty
}
where
initialVtable = M.fromList $ mapMaybe addIntrinsicF $ M.toList intrinsics
prim = Scalar . Prim
arrow x y = Scalar $ Arrow mempty Unnamed x y
addIntrinsicF (name, IntrinsicMonoFun pts t) =
Just (name, BoundV Global [] $ arrow pts' $ RetType [] $ prim t)
where
pts' = case pts of
[pt] -> prim pt
_ -> Scalar $ tupleRecord $ map prim pts
addIntrinsicF (name, IntrinsicOverloadedFun ts pts rts) =
Just (name, OverloadedF ts pts rts)
addIntrinsicF (name, IntrinsicPolyFun tvs pts rt) =
Just
( name,
BoundV Global tvs $
fromStruct $ Scalar $ Arrow mempty Unnamed pts' rt
)
where
pts' = case pts of
[pt] -> pt
_ -> Scalar $ tupleRecord pts
addIntrinsicF (name, IntrinsicEquality) =
Just (name, EqualityF)
addIntrinsicF _ = Nothing | 1,095 | initialTermScope =
TermScope
{ scopeVtable = initialVtable,
scopeTypeTable = mempty,
scopeNameMap = topLevelNameMap,
scopeModTable = mempty
}
where
initialVtable = M.fromList $ mapMaybe addIntrinsicF $ M.toList intrinsics
prim = Scalar . Prim
arrow x y = Scalar $ Arrow mempty Unnamed x y
addIntrinsicF (name, IntrinsicMonoFun pts t) =
Just (name, BoundV Global [] $ arrow pts' $ RetType [] $ prim t)
where
pts' = case pts of
[pt] -> prim pt
_ -> Scalar $ tupleRecord $ map prim pts
addIntrinsicF (name, IntrinsicOverloadedFun ts pts rts) =
Just (name, OverloadedF ts pts rts)
addIntrinsicF (name, IntrinsicPolyFun tvs pts rt) =
Just
( name,
BoundV Global tvs $
fromStruct $ Scalar $ Arrow mempty Unnamed pts' rt
)
where
pts' = case pts of
[pt] -> pt
_ -> Scalar $ tupleRecord pts
addIntrinsicF (name, IntrinsicEquality) =
Just (name, EqualityF)
addIntrinsicF _ = Nothing | 1,065 | false | true | 7 | 13 | 341 | 357 | 181 | 176 | null | null |
kyren/hsgb | lib/Gameboy/CPU.hs | unlicense | doInstruction (ADD_SP_N n) = do
sp <- getStackPointer
let (res, h, c) = add16 sp (fromIntegral n)
setFlags (Just False) (Just False) (Just h) (Just c)
setStackPointer res
tick 16 | 188 | doInstruction (ADD_SP_N n) = do
sp <- getStackPointer
let (res, h, c) = add16 sp (fromIntegral n)
setFlags (Just False) (Just False) (Just h) (Just c)
setStackPointer res
tick 16 | 188 | doInstruction (ADD_SP_N n) = do
sp <- getStackPointer
let (res, h, c) = add16 sp (fromIntegral n)
setFlags (Just False) (Just False) (Just h) (Just c)
setStackPointer res
tick 16 | 188 | false | false | 0 | 12 | 39 | 100 | 46 | 54 | null | null |
csakatoku/hello-yesod | test/TestImport.hs | bsd-2-clause | runDBWithApp :: App -> SqlPersistM a -> IO a
runDBWithApp app query = runSqlPersistMPool query (appConnPool app) | 112 | runDBWithApp :: App -> SqlPersistM a -> IO a
runDBWithApp app query = runSqlPersistMPool query (appConnPool app) | 112 | runDBWithApp app query = runSqlPersistMPool query (appConnPool app) | 67 | false | true | 0 | 7 | 16 | 41 | 19 | 22 | null | null |
hvr/text | tests/Tests/Properties.hs | bsd-2-clause | tl_rational = tl_read_rational TL.rational 1e-16 | 48 | tl_rational = tl_read_rational TL.rational 1e-16 | 48 | tl_rational = tl_read_rational TL.rational 1e-16 | 48 | false | false | 0 | 6 | 4 | 13 | 6 | 7 | null | null |
Zimmi48/gps-bank-data-analysis | XmlInputReader.hs | mpl-2.0 | name_amount_date ("DTPOSTED" : date : tl) = let (name , amount , Nothing) = name_amount_date tl in (name , amount , Just date) | 126 | name_amount_date ("DTPOSTED" : date : tl) = let (name , amount , Nothing) = name_amount_date tl in (name , amount , Just date) | 126 | name_amount_date ("DTPOSTED" : date : tl) = let (name , amount , Nothing) = name_amount_date tl in (name , amount , Just date) | 126 | false | false | 0 | 9 | 22 | 57 | 29 | 28 | null | null |
urbanslug/ghc | compiler/main/DynFlags.hs | bsd-3-clause | supportedExtensions :: [String]
supportedExtensions
= concatMap (\name -> [name, "No" ++ name]) (map flagSpecName xFlags) | 125 | supportedExtensions :: [String]
supportedExtensions
= concatMap (\name -> [name, "No" ++ name]) (map flagSpecName xFlags) | 125 | supportedExtensions
= concatMap (\name -> [name, "No" ++ name]) (map flagSpecName xFlags) | 93 | false | true | 0 | 9 | 18 | 48 | 25 | 23 | null | null |
jamesyang124/haskell-playground | src/Chp5.hs | bsd-3-clause | -- | Recursion with pattern matching
maximum1' [] = error "maximum of empty list" | 82 | maximum1' [] = error "maximum of empty list" | 44 | maximum1' [] = error "maximum of empty list" | 44 | true | false | 0 | 6 | 14 | 15 | 7 | 8 | null | null |
idf/haskell-examples | fundamentals/0_basics.hs | bsd-3-clause | -- | length
length' xs = sum [1 | _ <- xs] | 42 | length' xs = sum [1 | _ <- xs] | 30 | length' xs = sum [1 | _ <- xs] | 30 | true | false | 0 | 8 | 11 | 24 | 12 | 12 | null | null |
8l/barrelfish | tools/flounder/AHCI.hs | mit | ahci_header_file :: String -> Interface -> [C.Unit]
ahci_header_file infile interface@(Interface name descr decls) =
let
(types, messagedecls) = Backend.partitionTypesMessages decls
rpcs = [ rpc | rpc@(RPC _ _ _) <- messagedecls ]
rpc_msgs = concat $ map rpc_to_msgs rpcs
rx_rpc_msgs = [ msg | msg@(Message MResponse _ _ _) <- rpc_msgs ]
tx_rpc_msgs = [ msg | msg@(Message MCall _ _ _) <- rpc_msgs ]
ahci_ifn = ahci_intf_name name
in [
intf_preamble infile ahci_ifn descr,
C.Blank,
C.Include C.Standard $ "ahci/ahci.h",
C.Include C.Standard $ "if/" ++ name ++ "_defs.h",
C.Blank,
C.MultiComment [ "Forward declaration of binding type" ],
C.StructForwardDecl (ahci_bind_type ahci_ifn),
C.Blank,
C.MultiComment [ "The binding structure" ],
ahci_binding_struct name rpcs,
C.Blank,
C.MultiComment [ "Function to initialize an AHCI client" ],
ahci_init_fn_proto name,
C.Blank
] | 1,053 | ahci_header_file :: String -> Interface -> [C.Unit]
ahci_header_file infile interface@(Interface name descr decls) =
let
(types, messagedecls) = Backend.partitionTypesMessages decls
rpcs = [ rpc | rpc@(RPC _ _ _) <- messagedecls ]
rpc_msgs = concat $ map rpc_to_msgs rpcs
rx_rpc_msgs = [ msg | msg@(Message MResponse _ _ _) <- rpc_msgs ]
tx_rpc_msgs = [ msg | msg@(Message MCall _ _ _) <- rpc_msgs ]
ahci_ifn = ahci_intf_name name
in [
intf_preamble infile ahci_ifn descr,
C.Blank,
C.Include C.Standard $ "ahci/ahci.h",
C.Include C.Standard $ "if/" ++ name ++ "_defs.h",
C.Blank,
C.MultiComment [ "Forward declaration of binding type" ],
C.StructForwardDecl (ahci_bind_type ahci_ifn),
C.Blank,
C.MultiComment [ "The binding structure" ],
ahci_binding_struct name rpcs,
C.Blank,
C.MultiComment [ "Function to initialize an AHCI client" ],
ahci_init_fn_proto name,
C.Blank
] | 1,053 | ahci_header_file infile interface@(Interface name descr decls) =
let
(types, messagedecls) = Backend.partitionTypesMessages decls
rpcs = [ rpc | rpc@(RPC _ _ _) <- messagedecls ]
rpc_msgs = concat $ map rpc_to_msgs rpcs
rx_rpc_msgs = [ msg | msg@(Message MResponse _ _ _) <- rpc_msgs ]
tx_rpc_msgs = [ msg | msg@(Message MCall _ _ _) <- rpc_msgs ]
ahci_ifn = ahci_intf_name name
in [
intf_preamble infile ahci_ifn descr,
C.Blank,
C.Include C.Standard $ "ahci/ahci.h",
C.Include C.Standard $ "if/" ++ name ++ "_defs.h",
C.Blank,
C.MultiComment [ "Forward declaration of binding type" ],
C.StructForwardDecl (ahci_bind_type ahci_ifn),
C.Blank,
C.MultiComment [ "The binding structure" ],
ahci_binding_struct name rpcs,
C.Blank,
C.MultiComment [ "Function to initialize an AHCI client" ],
ahci_init_fn_proto name,
C.Blank
] | 1,001 | false | true | 0 | 14 | 304 | 310 | 164 | 146 | null | null |
shlevy/ghc | compiler/specialise/Rules.hs | bsd-3-clause | ruleCheck _ (Coercion _) = emptyBag | 38 | ruleCheck _ (Coercion _) = emptyBag | 38 | ruleCheck _ (Coercion _) = emptyBag | 38 | false | false | 1 | 6 | 8 | 20 | 8 | 12 | null | null |
alphaHeavy/cabal | cabal-install/Distribution/Client/Dependency/Modular/Dependency.hs | bsd-3-clause | goalReasonToVars :: GoalReason qpn -> ConflictSet qpn
goalReasonToVars UserGoal = S.empty | 105 | goalReasonToVars :: GoalReason qpn -> ConflictSet qpn
goalReasonToVars UserGoal = S.empty | 105 | goalReasonToVars UserGoal = S.empty | 51 | false | true | 0 | 6 | 26 | 30 | 13 | 17 | null | null |
dennis84/collab-haskell | test/Collab/Test/Util.hs | mit | withServerApp :: IO () -> IO ()
withServerApp action = do
thread <- forkIO runServerApp
waitSome
result <- action
killThread thread
return result | 155 | withServerApp :: IO () -> IO ()
withServerApp action = do
thread <- forkIO runServerApp
waitSome
result <- action
killThread thread
return result | 155 | withServerApp action = do
thread <- forkIO runServerApp
waitSome
result <- action
killThread thread
return result | 123 | false | true | 0 | 8 | 32 | 60 | 25 | 35 | null | null |
ianagbip1oti/ProC | src/ProC/Parser/ProC.hs | mit | exitBlockM :: Parser ()
exitBlockM = getState >>= liftIO . atomically . HM.pop >>= putState | 91 | exitBlockM :: Parser ()
exitBlockM = getState >>= liftIO . atomically . HM.pop >>= putState | 91 | exitBlockM = getState >>= liftIO . atomically . HM.pop >>= putState | 67 | false | true | 0 | 8 | 14 | 34 | 17 | 17 | null | null |
sgraf812/worklist | test/Main.hs | isc | huTests :: [TestTree]
huTests =
[ testGroup "Memoization"
[ testCase "fibonacci 10" (evaluate fibFramework 10 @?= fib 10)
, testCase "factorial 100" (evaluate facFramework 100 @?= fac 100)
]
, testGroup "mutual recursion"
[ testCase "stabilizes mutual recursive nodes" (evaluate mutualRecursiveFramework 1 @?= 10)
, testCase "stabilizes all nodes" (evaluate mutualRecursiveFramework 2 @?= 10)
]
] | 438 | huTests :: [TestTree]
huTests =
[ testGroup "Memoization"
[ testCase "fibonacci 10" (evaluate fibFramework 10 @?= fib 10)
, testCase "factorial 100" (evaluate facFramework 100 @?= fac 100)
]
, testGroup "mutual recursion"
[ testCase "stabilizes mutual recursive nodes" (evaluate mutualRecursiveFramework 1 @?= 10)
, testCase "stabilizes all nodes" (evaluate mutualRecursiveFramework 2 @?= 10)
]
] | 438 | huTests =
[ testGroup "Memoization"
[ testCase "fibonacci 10" (evaluate fibFramework 10 @?= fib 10)
, testCase "factorial 100" (evaluate facFramework 100 @?= fac 100)
]
, testGroup "mutual recursion"
[ testCase "stabilizes mutual recursive nodes" (evaluate mutualRecursiveFramework 1 @?= 10)
, testCase "stabilizes all nodes" (evaluate mutualRecursiveFramework 2 @?= 10)
]
] | 416 | false | true | 0 | 12 | 97 | 123 | 59 | 64 | null | null |
mikeplus64/trifecta | src/Text/Trifecta/Util/Array.hs | bsd-3-clause | thaw !ary !_o@(I# o#) !n@(I# n#) =
CHECK_LE("thaw", _o + n, length ary)
ST $ \ s -> case thawArray# (unArray ary) o# n# s of
(# s2, mary# #) -> (# s2, marray mary# n #)
#else
thaw !ary !o !n =
CHECK_LE("thaw", o + n, length ary)
do mary <- new_ n
copy ary o mary 0 n
return mary
#endif
| 308 | thaw !ary !_o@(I# o#) !n@(I# n#) =
CHECK_LE("thaw", _o + n, length ary)
ST $ \ s -> case thawArray# (unArray ary) o# n# s of
(# s2, mary# #) -> (# s2, marray mary# n #)
#else
thaw !ary !o !n =
CHECK_LE("thaw", o + n, length ary)
do mary <- new_ n
copy ary o mary 0 n
return mary
#endif
| 308 | thaw !ary !_o@(I# o#) !n@(I# n#) =
CHECK_LE("thaw", _o + n, length ary)
ST $ \ s -> case thawArray# (unArray ary) o# n# s of
(# s2, mary# #) -> (# s2, marray mary# n #)
#else
thaw !ary !o !n =
CHECK_LE("thaw", o + n, length ary)
do mary <- new_ n
copy ary o mary 0 n
return mary
#endif
| 308 | false | false | 1 | 10 | 85 | 107 | 54 | 53 | null | null |
Teaspot-Studio/gore-and-ash-logging | src/Game/GoreAndAsh/Logging/API.hs | bsd-3-clause | -- | Put error msg to console
logError :: LoggingMonad t m => Behavior t LogStr -> m ()
logError = logMsgLn LogError . fmap ("Error: " <>) | 138 | logError :: LoggingMonad t m => Behavior t LogStr -> m ()
logError = logMsgLn LogError . fmap ("Error: " <>) | 108 | logError = logMsgLn LogError . fmap ("Error: " <>) | 50 | true | true | 0 | 8 | 27 | 49 | 24 | 25 | null | null |
uuhan/Idris-dev | src/Idris/Core/TT.hs | bsd-3-clause | showCG (MN i s) = "{" ++ T.unpack s ++ "_" ++ show i ++ "}" | 59 | showCG (MN i s) = "{" ++ T.unpack s ++ "_" ++ show i ++ "}" | 59 | showCG (MN i s) = "{" ++ T.unpack s ++ "_" ++ show i ++ "}" | 59 | false | false | 0 | 10 | 15 | 42 | 19 | 23 | null | null |
jean-edouard/manager | disksync/Config.hs | gpl-2.0 | setVhdsyncVerbose :: Bool -> Rpc ()
setVhdsyncVerbose = dbWrite (diskSyncDBPath ++ "/vhdsync-verbose") | 102 | setVhdsyncVerbose :: Bool -> Rpc ()
setVhdsyncVerbose = dbWrite (diskSyncDBPath ++ "/vhdsync-verbose") | 102 | setVhdsyncVerbose = dbWrite (diskSyncDBPath ++ "/vhdsync-verbose") | 66 | false | true | 0 | 7 | 11 | 30 | 15 | 15 | null | null |
conal/TV | src/Interface/TV/IO.hs | bsd-3-clause | {----------------------------------------------------------
Outputs
----------------------------------------------------------}
-- | Equivalent of 'interact'. See also 'Interface.TV.interactLine'
interactOut :: Output IO OI (String -> String)
interactOut = oLambda contentsIn stringOut | 291 | interactOut :: Output IO OI (String -> String)
interactOut = oLambda contentsIn stringOut | 89 | interactOut = oLambda contentsIn stringOut | 42 | true | true | 0 | 7 | 29 | 32 | 17 | 15 | null | null |
joelchelliah/rock-paper-scissors-hs | src/Printer.hs | bsd-3-clause | indent :: String -> String
indent = (" " ++) | 45 | indent :: String -> String
indent = (" " ++) | 45 | indent = (" " ++) | 18 | false | true | 0 | 5 | 10 | 19 | 11 | 8 | null | null |
dinkelk/redo | src/FilePathUtil.hs | mit | unescapeFilePath :: FilePath -> FilePath
unescapeFilePath "" = "" | 65 | unescapeFilePath :: FilePath -> FilePath
unescapeFilePath "" = "" | 65 | unescapeFilePath "" = "" | 24 | false | true | 0 | 5 | 8 | 18 | 9 | 9 | null | null |
onponomarev/ganeti | src/Ganeti/Constants.hs | bsd-2-clause | hvDiskCache :: String
hvDiskCache = "disk_cache" | 48 | hvDiskCache :: String
hvDiskCache = "disk_cache" | 48 | hvDiskCache = "disk_cache" | 26 | false | true | 0 | 6 | 5 | 18 | 7 | 11 | null | null |
jgm/pandoc-types | src/Text/Pandoc/Walk.hs | bsd-3-clause | walkMetaValueM f (MetaInlines xs) = MetaInlines <$> walkM f xs | 62 | walkMetaValueM f (MetaInlines xs) = MetaInlines <$> walkM f xs | 62 | walkMetaValueM f (MetaInlines xs) = MetaInlines <$> walkM f xs | 62 | false | false | 0 | 7 | 9 | 26 | 12 | 14 | null | null |
NCrashed/hjass | src/library/Language/Jass/Parser/Grammar.hs | mit | getPosition' :: JassParser SrcPos
getPosition' = do
pos <- getPosition
return $ SrcPos (sourceName pos) (sourceLine pos) (sourceColumn pos) | 147 | getPosition' :: JassParser SrcPos
getPosition' = do
pos <- getPosition
return $ SrcPos (sourceName pos) (sourceLine pos) (sourceColumn pos) | 147 | getPosition' = do
pos <- getPosition
return $ SrcPos (sourceName pos) (sourceLine pos) (sourceColumn pos) | 113 | false | true | 0 | 10 | 26 | 53 | 25 | 28 | null | null |
anttisalonen/cgen | src/Options.hs | bsd-3-clause | parseInterfaceFile fun (l:ls) opts = do
ofun <- fun l
parseInterfaceFile fun ls (ofun opts) | 99 | parseInterfaceFile fun (l:ls) opts = do
ofun <- fun l
parseInterfaceFile fun ls (ofun opts) | 99 | parseInterfaceFile fun (l:ls) opts = do
ofun <- fun l
parseInterfaceFile fun ls (ofun opts) | 99 | false | false | 0 | 9 | 22 | 46 | 21 | 25 | null | null |
brendanhay/gogol | gogol-dfareporting/gen/Network/Google/Resource/DFAReporting/Advertisers/List.hs | mpl-2.0 | -- | Select only advertisers which do not belong to any advertiser group.
allIncludeAdvertisersWithoutGroupsOnly :: Lens' AdvertisersList (Maybe Bool)
allIncludeAdvertisersWithoutGroupsOnly
= lens _allIncludeAdvertisersWithoutGroupsOnly
(\ s a ->
s{_allIncludeAdvertisersWithoutGroupsOnly = a}) | 311 | allIncludeAdvertisersWithoutGroupsOnly :: Lens' AdvertisersList (Maybe Bool)
allIncludeAdvertisersWithoutGroupsOnly
= lens _allIncludeAdvertisersWithoutGroupsOnly
(\ s a ->
s{_allIncludeAdvertisersWithoutGroupsOnly = a}) | 237 | allIncludeAdvertisersWithoutGroupsOnly
= lens _allIncludeAdvertisersWithoutGroupsOnly
(\ s a ->
s{_allIncludeAdvertisersWithoutGroupsOnly = a}) | 160 | true | true | 0 | 9 | 46 | 48 | 25 | 23 | null | null |
Shimuuar/protobuf | Data/Protobuf/Internal/Names.hs | bsd-3-clause | mergeNamespaces :: Namespace -> Namespace -> PbMonadE Namespace
mergeNamespaces namespace (Namespace ns2)
= F.foldlM insertName namespace ns2 | 143 | mergeNamespaces :: Namespace -> Namespace -> PbMonadE Namespace
mergeNamespaces namespace (Namespace ns2)
= F.foldlM insertName namespace ns2 | 143 | mergeNamespaces namespace (Namespace ns2)
= F.foldlM insertName namespace ns2 | 79 | false | true | 0 | 7 | 18 | 42 | 20 | 22 | null | null |
nomeata/cryptonite | Crypto/Cipher/ChaChaPoly1305.hs | bsd-3-clause | appendAAD :: ByteArrayAccess ba => ba -> State -> State
appendAAD ba (State encState macState aadLength plainLength) =
State encState newMacState newLength plainLength
where
newMacState = Poly1305.update macState ba
newLength = aadLength + fromIntegral (B.length ba) | 282 | appendAAD :: ByteArrayAccess ba => ba -> State -> State
appendAAD ba (State encState macState aadLength plainLength) =
State encState newMacState newLength plainLength
where
newMacState = Poly1305.update macState ba
newLength = aadLength + fromIntegral (B.length ba) | 282 | appendAAD ba (State encState macState aadLength plainLength) =
State encState newMacState newLength plainLength
where
newMacState = Poly1305.update macState ba
newLength = aadLength + fromIntegral (B.length ba) | 226 | false | true | 1 | 9 | 51 | 95 | 43 | 52 | null | null |
kojiromike/Idris-dev | src/Idris/Options.hs | bsd-3-clause | getCodegenArgs :: Opt -> Maybe String
getCodegenArgs (CodegenArgs args) = Just args | 83 | getCodegenArgs :: Opt -> Maybe String
getCodegenArgs (CodegenArgs args) = Just args | 83 | getCodegenArgs (CodegenArgs args) = Just args | 45 | false | true | 0 | 7 | 11 | 30 | 14 | 16 | null | null |
mongodb-haskell/mongodb | Database/MongoDB/Admin.hs | apache-2.0 | removeUser :: (MonadIO m)
=> Username -> Action m ()
removeUser user = delete (select ["user" =: user] "system.users") | 129 | removeUser :: (MonadIO m)
=> Username -> Action m ()
removeUser user = delete (select ["user" =: user] "system.users") | 129 | removeUser user = delete (select ["user" =: user] "system.users") | 65 | false | true | 0 | 9 | 29 | 57 | 27 | 30 | null | null |
conal/lambda-ccc | src/LambdaCCC/Unused/ReifyLambda.hs | bsd-3-clause | -- inlineNamesTD :: [String] -> RewriteH Core
-- inlineNamesTD nms = anytdER (inlineNamesR nms)
-- #define FactorReified
reifyNamed :: String -> RewriteH Core
reifyNamed nm = snocPathIn (rhsOfT cmpNm)
( inlineCleanup (lamName "ifThenElse")
-- >>> (tryR $ anytdER $ rule "if/pair")
>>> reifyExprC
>>> reifyRules
#ifdef FactorReified
>>> pathR [App_Arg] (promoteExprR (letIntroR (nm ++ "_reified")))
>>> promoteExprR letFloatArgR
#endif
)
#ifdef FactorReified
>>> snocPathIn (extractT $ parentOfT $ bindingGroupOfT $ cmpNm)
(promoteProgR letFloatTopR)
#endif
>>> inlineCleanup nm
-- I don't know why the following is needed, considering the INLINE
>>> inlineCleanup (lamName "reifyEP#")
-- >>> tryR (anybuER (promoteExprR reifyEval))
-- >>> tryRulesBU ["reifyE/evalE","evalE/reifyE"]
-- >>> tryRulesBU ["reifyEP/evalEP"]
>>> tryR simplifyR -- For the rule applications at least
where
cmpNm = cmpString2Var nm
-- I don't know why I need both cleanupUnfoldR and simplifyR.
-- Note: I inline reifyE to its reifyE definition and then simplify
-- reifyE/evalE, rather than simplifying reifyE/evalE. With this choice, I can
-- also reifyE/evalE combinations that come from reifyE in source code and ones
-- that reifyExpr inserts.
{--------------------------------------------------------------------
Plugin
--------------------------------------------------------------------} | 1,625 | reifyNamed :: String -> RewriteH Core
reifyNamed nm = snocPathIn (rhsOfT cmpNm)
( inlineCleanup (lamName "ifThenElse")
-- >>> (tryR $ anytdER $ rule "if/pair")
>>> reifyExprC
>>> reifyRules
#ifdef FactorReified
>>> pathR [App_Arg] (promoteExprR (letIntroR (nm ++ "_reified")))
>>> promoteExprR letFloatArgR
#endif
)
#ifdef FactorReified
>>> snocPathIn (extractT $ parentOfT $ bindingGroupOfT $ cmpNm)
(promoteProgR letFloatTopR)
#endif
>>> inlineCleanup nm
-- I don't know why the following is needed, considering the INLINE
>>> inlineCleanup (lamName "reifyEP#")
-- >>> tryR (anybuER (promoteExprR reifyEval))
-- >>> tryRulesBU ["reifyE/evalE","evalE/reifyE"]
-- >>> tryRulesBU ["reifyEP/evalEP"]
>>> tryR simplifyR -- For the rule applications at least
where
cmpNm = cmpString2Var nm
-- I don't know why I need both cleanupUnfoldR and simplifyR.
-- Note: I inline reifyE to its reifyE definition and then simplify
-- reifyE/evalE, rather than simplifying reifyE/evalE. With this choice, I can
-- also reifyE/evalE combinations that come from reifyE in source code and ones
-- that reifyExpr inserts.
{--------------------------------------------------------------------
Plugin
--------------------------------------------------------------------} | 1,502 | reifyNamed nm = snocPathIn (rhsOfT cmpNm)
( inlineCleanup (lamName "ifThenElse")
-- >>> (tryR $ anytdER $ rule "if/pair")
>>> reifyExprC
>>> reifyRules
#ifdef FactorReified
>>> pathR [App_Arg] (promoteExprR (letIntroR (nm ++ "_reified")))
>>> promoteExprR letFloatArgR
#endif
)
#ifdef FactorReified
>>> snocPathIn (extractT $ parentOfT $ bindingGroupOfT $ cmpNm)
(promoteProgR letFloatTopR)
#endif
>>> inlineCleanup nm
-- I don't know why the following is needed, considering the INLINE
>>> inlineCleanup (lamName "reifyEP#")
-- >>> tryR (anybuER (promoteExprR reifyEval))
-- >>> tryRulesBU ["reifyE/evalE","evalE/reifyE"]
-- >>> tryRulesBU ["reifyEP/evalEP"]
>>> tryR simplifyR -- For the rule applications at least
where
cmpNm = cmpString2Var nm
-- I don't know why I need both cleanupUnfoldR and simplifyR.
-- Note: I inline reifyE to its reifyE definition and then simplify
-- reifyE/evalE, rather than simplifying reifyE/evalE. With this choice, I can
-- also reifyE/evalE combinations that come from reifyE in source code and ones
-- that reifyExpr inserts.
{--------------------------------------------------------------------
Plugin
--------------------------------------------------------------------} | 1,464 | true | true | 0 | 19 | 431 | 177 | 95 | 82 | null | null |
energyflowanalysis/efa-2.1 | attic/src/EFA2/Solver/Horn.hs | bsd-3-clause | makeAnd :: NonEmpty.T [] Formula -> Formula
makeAnd = NonEmpty.foldl1 And | 73 | makeAnd :: NonEmpty.T [] Formula -> Formula
makeAnd = NonEmpty.foldl1 And | 73 | makeAnd = NonEmpty.foldl1 And | 29 | false | true | 0 | 8 | 10 | 35 | 15 | 20 | null | null |
yupferris/write-you-a-haskell | chapter7/poly/src/Main.hs | mit | -------------------------------------------------------------------------------
-- Toplevel
-------------------------------------------------------------------------------
main :: IO ()
main = do
args <- getArgs
case args of
[] -> shell (return ())
[fname] -> shell (load [fname])
["test", fname] -> shell (load [fname] >> browse [] >> quit ())
_ -> putStrLn "invalid arguments" | 404 | main :: IO ()
main = do
args <- getArgs
case args of
[] -> shell (return ())
[fname] -> shell (load [fname])
["test", fname] -> shell (load [fname] >> browse [] >> quit ())
_ -> putStrLn "invalid arguments" | 231 | main = do
args <- getArgs
case args of
[] -> shell (return ())
[fname] -> shell (load [fname])
["test", fname] -> shell (load [fname] >> browse [] >> quit ())
_ -> putStrLn "invalid arguments" | 217 | true | true | 0 | 16 | 69 | 130 | 63 | 67 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.