Created
September 16, 2012 23:21
-
-
Save sviperll/3734802 to your computer and use it in GitHub Desktop.
More thoughts on new lazy pure functional programming language to run on JVM
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
class List implements Monad { | |
(:), nil, (++), null public; | |
(:), nil constructor; | |
(:) :: forall a. a -> this a -> this a; | |
nil :: forall a. this a; | |
(++) :: forall a. List a -> List a -> List a; | |
(x:?xs) ++ ys = x : (xs ++ ys); | |
nil? ++ ys = ys; | |
null :: forall a. List a -> Bool; | |
null nil? = true; | |
null (x:?xs) = false; | |
return, join implementation; | |
return a = cons a nil; | |
join nil? = []; | |
join (x:?xs) = x ++ join xs; | |
} | |
interface Functor { | |
fmap :: (a -> b) -> (this a -> this b) | |
} | |
interface Monad extends Functor { | |
return :: forall a. this a; | |
join :: forall a. this (this a) -> this a; | |
join = (>>= id) | |
(>>=) infix right 5; | |
(>>=) :: forall a b. this a -> (a -> this b) -> this b; | |
a >>= f = join (fmap f a) | |
fmap implementation | |
fmap f = (>>= (return . f)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment