Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Trying to prove Applicative is superclass of Functor, etc (Silent Leaf) ---------------------------------------------------------------------- Message: 1 Date: Sun, 1 May 2016 11:56:11 +0200 From: Silent Leaf <silent.le...@gmail.com> To: Daniel Bergey <ber...@alum.mit.edu>, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Trying to prove Applicative is superclass of Functor, etc Message-ID: <cagfccjooatyzw5zv9hqtuqe5zsyqkpxzujyyaewoqbx5pgr...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I see, thanks for all this information! Here must be the answer of why, possibly, liftM is written in terms of monads and not of fmap. Yes I was saying "not heavywork" at the time I didn't know you could create an instance of Monad and use its methods to fill the superclasses even though intuitively it looked like the Monad instance couldn't be accepted if the superclass weren't already. Does anyone have an explanation for this? Le samedi 30 avril 2016, Daniel Bergey <ber...@alum.mit.edu> a ?crit : > On 2016-04-30 at 15:14, Silent Leaf <silent.le...@gmail.com> wrote: >> I think I got what exactly was the change of ghc 7.10. basically it only adds a >> constraint Applicative on the Monad class, and same with >> Functor/Applicative. > > 7.10 adds the constraint on the Monad class. Prior to 7.10, both Monads > and Applicatives already needed to be Functors. > >> Otherwise it's forcing the programmer to do even more possibly-useless >> work (we don't always need applicative and functors for every use of a >> new monad, do we?) > > The practical advantage comes when I want to write some code that is > generic over Monads. If I can't assume that every Monad is Applicative, > my choices are: > > 1) Write (Applicative m, Monad m) =>, and not work for those Monads > 2) Write `ap` everywhere I mean <*>, which for some instances is less > efficient > 3) Write two versions, one like (1) and one like (2) > > None of these are very appealing, and orphan instances are a pain, so > there's already strong social pressure that any Monad instance on > Hackage should have the corresponding Applicative instance defined. > >> in short i think if they wanted mathematical correctness they should >> have added automatic instanciation of superclasses, with possibility >> to override the default definitions, like they do so with some >> superfluous methods. > > Several ways of automatically defining superclasses were discussed as > part of the AMP changes. Maybe we'll get one in some future GHC. I > don't know the details, but some of the discussion: > > https://ghc.haskell.org/trac/ghc/wiki/IntrinsicSuperclasses > https://ghc.haskell.org/trac/ghc/wiki/DefaultSuperclassInstances > https://ghc.haskell.org/trac/ghc/wiki/InstanceTemplates > >> Not that write functors or applicative functor instances is actually heavywork, of >> course, thankfully. > > You know that if the instances are all in the same module, you can use > the Monad functions, right? So the extra work is just pasting in: > > instance Functor m where > fmap = liftM > > instance Applicative m where > pure = return > (<*>) = ap > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160501/5ce58929/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 95, Issue 2 ****************************************