... | ... | @@ -16,9 +16,12 @@ classMonad m where |
|
|
(<*>)= ap
|
|
|
|
|
|
instance Monad Maybe where
|
|
|
return =JustNothing>>=_=Nothing(Just x)>>= f = f x
|
|
|
return = Just
|
|
|
Nothing >>= _ = Nothing
|
|
|
(Just x) >>= f = f x
|
|
|
|
|
|
deriving(Functor,Applicative)-- these inherit the constraints and params above-- ORderivinginstanceFunctor m
|
|
|
deriving (Functor, Applicative) -- these inherit the constraints and params above
|
|
|
-- OR deriving instance Functor m
|
|
|
deriving instance Applicative m -- these specify constraints
|
|
|
```
|
|
|
|
... | ... | @@ -105,7 +108,9 @@ classFunctor f =>Applicative f where |
|
|
(<*>) :: f (a -> b) -> f a -> f b
|
|
|
|
|
|
deriving default instance Functor f where
|
|
|
fmap f =(pure f <*>)classApplicative m =>Monad m where
|
|
|
fmap f = (pure f <*>)
|
|
|
|
|
|
class Applicative m => Monad m where
|
|
|
return :: a -> m a
|
|
|
(>>=):: m a ->(a -> m b)-> m b
|
|
|
fail ::String-> m a
|
... | ... | @@ -128,7 +133,8 @@ This proposal does not address directly how to split a class into pieces, but th |
|
|
Here is a class we want to split:
|
|
|
|
|
|
```
|
|
|
classNum a where(+):: a -> a -> a
|
|
|
class Num a where
|
|
|
(+):: a -> a -> a
|
|
|
(*):: a -> a -> a
|
|
|
```
|
|
|
|
... | ... | @@ -141,15 +147,18 @@ classAdditive a where |
|
|
class Multiplicative a where
|
|
|
mult :: a -> a -> a
|
|
|
|
|
|
class(Additive a,Multiplicative a)=>Num a where(+):: a -> a -> a
|
|
|
class (Additive a, Multiplicative a) => Num a where
|
|
|
(+):: a -> a -> a
|
|
|
(+) = add
|
|
|
|
|
|
(*):: a -> a -> a
|
|
|
(*) = mult
|
|
|
|
|
|
deriving default instance Additive a where
|
|
|
add =(+)derivingdefaultinstanceMultiplicative a where
|
|
|
mult =(*){-# MINIMAL (add | (+)), (mult | (*)) #-}
|
|
|
add =(+)
|
|
|
deriving default instance Multiplicative a where
|
|
|
mult =(*)
|
|
|
{-# MINIMAL (add | (+)), (mult | (*)) #-}
|
|
|
```
|
|
|
|
|
|
|
... | ... | |