[Haskell-cafe] MRP, 3-year-support-window, and the non-requirement of CPP

Edward Kmett ekmett at gmail.com
Sat Oct 10 19:16:10 UTC 2015


On Wed, Oct 7, 2015 at 3:35 AM, Herbert Valerio Riedel <hvr at gnu.org> wrote:

> --8<---------------cut here---------------start------------->8---
> import Control.Applicative as A (Applicative(..))
>
> data Maybe' a = Nothing' | Just' a
>
> instance Functor Maybe' where
>     fmap f (Just' v) = Just' (f v)
>     fmap _ Nothing'  = Nothing'
>
> instance A.Applicative Maybe' where
>     pure = Just'
>     f1 <*> f2   = f1 >>= \v1 -> f2 >>= (pure . v1)
>
> instance Monad Maybe' where
>     Nothing' >>= _  = Nothing'
>     Just' x  >>= f  = f x
>
>     return = pure -- "deprecated" since GHC 7.10
> --8<---------------cut here---------------end--------------->8---
>
>
Alternately,

import Control.Applicative
import Prelude

data Maybe' a = Nothing' | Just' a

instance Functor Maybe' where
    fmap f (Just' v) = Just' (f v)
    fmap _ Nothing'  = Nothing'

instance Applicative Maybe' where



> -- hvr
> _______________________________________________
> Haskell-prime mailing list
> Haskell-prime at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20151010/14bf5791/attachment.html>


More information about the Libraries mailing list