Last active
May 15, 2017 11:20
-
-
Save marinelli/c5431aeb213f9e61504b489611ce34f4 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE | |
UnicodeSyntax | |
, InstanceSigs | |
, KindSignatures | |
, RankNTypes | |
#-} | |
module MAF | |
where | |
import Prelude | |
hiding (fmap, pure) | |
class Functors (t ∷ * → *) | |
where | |
fmap ∷ forall a b . (a → b) → t a → t b | |
class (Functors t) ⇒ | |
Applicatives (t ∷ * → *) | |
where | |
pure ∷ forall a . a → t a | |
appl ∷ forall a b . t (a → b) → t a → t b | |
class (Applicatives t) ⇒ | |
Monads (t ∷ * → *) | |
where | |
retu ∷ forall a . a → t a | |
bind ∷ forall a b . t a → (a → t b) → t b | |
instance Functors [] | |
where | |
fmap ∷ forall a b . (a → b) → [] a → [] b | |
fmap = map | |
instance Applicatives [] | |
where | |
pure ∷ forall a . a → [] a | |
pure = \ x → [x] | |
appl ∷ forall a b . [] (a → b) → [] a → [] b | |
appl = \ fs xs → concat (map (\ f → map (\ x → f x) xs) fs) | |
instance Monads [] | |
where | |
retu ∷ forall a . a → [] a | |
retu = pure | |
bind ∷ forall a b . [] a → (a → [] b) → [] b | |
bind = \ l f → concat $ map f l | |
-- ⋅ -- | |
class (Monads t) ⇒ | |
Functorm (t ∷ * → *) | |
where | |
fmapm ∷ forall a b . (a → b) → t a → t b | |
fmapm = \ f m → m `bind` (\ x → retu $ f x) | |
class (Monads t) ⇒ | |
Applicativem (t ∷ * → *) | |
where | |
purem ∷ forall a . a → t a | |
purem = retu | |
applm ∷ forall a b . t (a → b) → t a → t b | |
applm = \ mf mx → mf `bind` (\ f → mx `bind` (\ x → purem $ f x)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment