[Haskell-beginners] How to create a monad in GHC 7.10 or newer
Ahmad Ismail
ismail783 at gmail.com
Sun Nov 13 15:47:33 UTC 2022
Thank you very much.
*Thanks and Best Regards,Ahmad Ismail*
On Sun, Nov 13, 2022 at 9:22 PM Francesco Ariis <fa-ml at ariis.it> wrote:
> Il 13 novembre 2022 alle 20:56 Ahmad Ismail ha scritto:
> > How can I fix it so that `ItDoesnt <*> WhatThisIsCalled` works?
> >
> > I have came up with a solution without WhatThisIsCalled
> >
> > data WhoCares a = ItDoesnt | Matter a deriving (Eq, Show)
> >
> > instance Functor WhoCares where
> > fmap _ ItDoesnt = ItDoesnt
> > fmap f (Matter a) = Matter (f a)
> >
> > instance Applicative WhoCares where
> > pure = Matter
> > Matter f <*> Matter a = Matter (f a)
> > ItDoesnt <*> _ = ItDoesnt
> > _ <*> ItDoesnt = ItDoesnt
> >
> > instance Monad WhoCares where
> > return x = Matter x
> > (Matter x) >>= k = k x
> > ItDoesnt >>= _ = ItDoesnt
>
> This makes much more sense. Now <*> is total and >>= is meaningful,
> well done!
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20221113/2ec854f7/attachment.html>
More information about the Beginners
mailing list