Skip to content

Instantly share code, notes, and snippets.

@pminten
Created April 23, 2014 16:53
Show Gist options
  • Save pminten/11223315 to your computer and use it in GitHub Desktop.
Save pminten/11223315 to your computer and use it in GitHub Desktop.
Functions can be lazy based on computations
module Main
pl : Bool -> Type -> Type
pl True t = Lazy t
pl False t = t
-- Only defined for True.
partial
onlyTrue : Bool -> Bool
onlyTrue True = True
strictAnd : Bool -> pl False Bool -> Bool
strictAnd True b = b
strictAnd False _ = False
lazyAnd : Bool -> pl True Bool -> Bool
lazyAnd True b = b
lazyAnd False _ = False
-- If you type more than 2 characters and press enter the program crashes.
-- If you replace lazyAnd with strictAnd it crashes regardless of the number of
-- characters.
main : IO ()
main = do
l <- getLine
if lazyAnd (length l > 2) (onlyTrue False)
then putStrLn "A"
else putStrLn "B"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment