Skip to content

@rares /gist:304013
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Monad
type Choice a = [a]
choose :: [a] -> Choice a
choose xs = xs
-- Join
join :: Choice (Choice a) -> Choice a
join choices = concat choices
-- Bind
(>>=) :: Choice a -> (a -> Choice b) -> Choice b
choices >>= f = join (map f choices)
-- Bind (ignore original)
(>>) :: Choice a -> Choice b -> Choice b
choices >> f = choices >>= \_ -> f
-- Return
return :: a -> Choice a
return x = choose [x]
-- Guard
mzero :: Choice a
mzero = choose []
guard :: Bool -> Choice ()
guard True = return ()
guard False = mzero
test' :: Choice (Int, Int, Int)
test' = do
x <- choose [1,2,3]
y <- choose [4,5,6]
z <- choose [7,8,9]
guard ((x + y) * z == 45)
return (x, y, z)
main = do
print(take 1 test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.