[Haskell-beginners] Trying to prove Applicative is superclass of Functor, etc
Silent Leaf
silent.leaf0 at gmail.com
Sun May 1 09:56:11 UTC 2016
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 <bergey at alum.mit.edu> a écrit :
> On 2016-04-30 at 15:14, Silent Leaf <silent.leaf0 at 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.html>
More information about the Beginners
mailing list