@@ -170,6 +170,17 @@ module Prelude
170 infixl 4 <$>
170 infixl 4 <$>
171 infixl 1 <#>
171 infixl 1 <#>
173+ -- | A Functor is intuitively a type which can be mapped over, and more formally a mapping
174+ -- | between categories that preserves structure.
176+ -- | Functors should obey the following rules.
182+ -- | forall f g. (<$>) (f . g) = ((<$>) f) . ((<$>) g)
173 class Functor f where
184 class Functor f where
174 (<$>) :: forall a b. (a -> b) -> f a -> f b
185 (<$>) :: forall a b. (a -> b) -> f a -> f b
@@ -181,9 +192,34 @@ module Prelude
182 infixl 4 <*>
193 infixl 4 <*>
195+ -- | Applys are intuitively Applicatives less `pure`, and more formally a strong lax semi-
196+ -- | -monoidal endofunctor.
198+ -- | Applys should obey the following rules.
200+ -- | Associative Composition
201+ -- | forall f g h. (.) <$> f <*> g <*> h = f <*> (g <*> h)
184 class (Functor f) <= Apply f where
203 class (Functor f) <= Apply f where
185 (<*>) :: forall a b. f (a -> b) -> f a -> f b
204 (<*>) :: forall a b. f (a -> b) -> f a -> f b
206+ -- | Applicatives are Functors which can be "applied" by sequencing composition (<*>) or embedding
207+ -- | pure expressions (pure).
209+ -- | Applicatives should obey the following rules.
212+ -- | forall v. (pure id) <*> v = v
215+ -- | forall f g h. (pure (.)) <*> f <*> g <*> h = f <*> (g <*> h)
218+ -- | forall f x. (pure f) <*> (pure x) = pure (f x)
221+ -- | forall u y. u <*> (pure y) = (pure (($) y)) <*> u
187 class (Apply f) <= Applicative f where
223 class (Apply f) <= Applicative f where
188 pure :: forall a. a -> f a
224 pure :: forall a. a -> f a
@@ -192,9 +228,30 @@ module Prelude
193 infixl 1 >>=
229 infixl 1 >>=
231+ -- | A Bind is an Apply with a bind operation which sequentially composes actions.
233+ -- | A Bind should obey the following rule.
235+ -- | Associative (as Bind)
236+ -- | forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)
195 class (Apply m) <= Bind m where
238 class (Apply m) <= Bind m where
196 (>>=) :: forall a b. m a -> (a -> m b) -> m b
239 (>>=) :: forall a b. m a -> (a -> m b) -> m b
241+ -- | Monad is a class which can be intuitively thought of as an abstract datatype of actions or
242+ -- | more formally though of as a monoid in the category of endofunctors.
244+ -- | A Monad should obey the following rules.
246+ -- | Associative (as Bind)
247+ -- | forall f g x. (x >>= f) >>= g = x >>= (\k => f k >>= g)
250+ -- | forall f x. pure x >>= f = f x
253+ -- | forall x. x >>= pure = x
198 class (Applicative m, Bind m) <= Monad m
255 class (Applicative m, Bind m) <= Monad m
200 return :: forall m a. (Monad m) => a -> m a
257 return :: forall m a. (Monad m) => a -> m a