on master help sign in
Functor and Applicative instances for Identity.
commitd13c4bafc624430f134d18e93a2ed713ca6c3ece authorstartling <tdixon51793@gmail.com> dateMon 19 Nov 2012, 12:06 (14 years ago) parent694bf20
1 file changed+10
lib/Control/Monad/Identity.idr+10
lib/Control/Monad/Identity.idr+10
@@ -1,10 +1,20 @@
11module Control.Monad.Identity
22
3+import Prelude.Functor
4+import Prelude.Applicative
35import Prelude.Monad
46
57public record Identity : Set -> Set where
68 Id : (runIdentity : a) -> Identity a
79
10+instance Functor Identity where
11+ fmap fn (Id a) = Id (fn a)
12+
13+instance Applicative Identity where
14+ pure x = Id x
15+
16+ (Id f) <$> (Id g) = Id (f g)
17+
818instance Monad Identity where
919 return x = Id x
1020 (Id x) >>= k = k x