Created
July 1, 2010 14:59
-
-
Save sadache/460064 to your computer and use it in GitHub Desktop.
This file contains 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 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
http://hackage.haskell.org/packages/archive/monad-param/0.0.2/doc/html/Control-Monad-Parameterized.html