Skip to content

Instantly share code, notes, and snippets.

@sadache
Created July 1, 2010 14:59
Show Gist options
  • Save sadache/460064 to your computer and use it in GitHub Desktop.
Save sadache/460064 to your computer and use it in GitHub Desktop.
module Main where
class Monad64 a ma mb | ma mb -> a where
(>>==) :: ma -> ( a -> mb) -> mb
data Maybe64 a = Just64 a
|Nothing64
deriving Show
instance Monad64 a (Maybe64 a) (Maybe64 b) where
(>>==) m f = case m of Just64 a -> f a
_ -> Nothing64
instance Monad64 a (Maybe64 a) (Maybe b) where
(>>==) m f = case m of Just64 a -> f a
_ -> Nothing
instance Monad64 a (Maybe a) ([b]) where
(>>==) m f = case m of Just a -> f a
_ -> []
instance Monad64 a (Maybe [a]) (Maybe [b]) where
(>>==) m f = case m of Just xs -> Just [ k | x <- xs , let ks = (maybe [] id) (f x), k <- ks]
_ -> Nothing
main= print another >> print doSomething
doSomething = ((Just64 1) >>== \i ->
Just (i*2)) >>== \j ->
[j]
another= Just [1,2,3] >>== \a ->
if a < 3 then Just [a] else Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment