Created
April 23, 2014 16:53
-
-
Save pminten/11223315 to your computer and use it in GitHub Desktop.
Functions can be lazy based on computations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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