Skip to content

Instantly share code, notes, and snippets.

@rockymadden
Forked from gclaramunt/Functor.scala
Created December 18, 2013 18:24
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 rockymadden/8027233 to your computer and use it in GitHub Desktop.
Save rockymadden/8027233 to your computer and use it in GitHub Desktop.
trait Functor[T[_]]{
def fmap[A,B](f:A=>B)(ta:T[A]):T[B]
}
trait Applicative[T[_]] extends Functor[T]{
def pure[A](a:A):T[A]
def <*>[A,B](tf:T[A=>B])(ta:T[A]):T[B]
}
trait Monad[M[_]] extends Applicative[M]{
def >>=[A,B](ma:M[A])(f:A=>M[B]):M[B]
}
-- from "Learn you a Haskell for great good"
class Functor f where
fmap :: (a -> b) -> f a -> f b
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
class (Applicative m) = > Monad m where
(>>=) :: m a -> (a -> m b) -> m b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment