Skip to content

Instantly share code, notes, and snippets.

@sviperll
Created September 16, 2012 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sviperll/3734802 to your computer and use it in GitHub Desktop.
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
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