Functor, Applicative Functor, Monad typeclasses in Haskell and their (simplistic) Scala translation
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
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] | |
} |
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
-- 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
<3