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. Trying to prove Applicative is superclass of Functor, etc (Silent Leaf) 2. Re: Trying to prove Applicative is superclass of Functor, etc (Silent Leaf) 3. Re: Trying to prove Applicative is superclass of Functor, etc (D?niel Arat?) 4. Re: Trying to prove Applicative is superclass of Functor, etc (D?niel Arat?) 5. Re: Trying to prove Applicative is superclass of Functor, etc (Silent Leaf) 6. Re: Trying to prove Applicative is superclass of Functor, etc (Silent Leaf) ---------------------------------------------------------------------- Message: 1 Date: Fri, 29 Apr 2016 11:14:15 +0200 From: Silent Leaf <silent.le...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Trying to prove Applicative is superclass of Functor, etc Message-ID: <cagfccjpyas_vy635uhf7fbdpxb-drnb303ij2ao5zw0ozl6...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi, well aware it's trivial so I'll be terse: do we have?: > fmap = <*> . pure So we could write for example > liftA2 f fa fb = f <$> fa <*> fb this way?: > liftA2 f fa fb = pure f <*> fa <*> fb <*> Incidentally, do we have?: > liftA == liftM == fmap Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160429/6b8ec5ab/attachment-0001.html> ------------------------------ Message: 2 Date: Fri, 29 Apr 2016 11:20:15 +0200 From: Silent Leaf <silent.le...@gmail.com> To: 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: <cagfccjnbbmqc1zg+sxrqxyorno9hbft9hfqsu2gk1mlxsha...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Oh, and by the way, is it enough then to create an instance of Applicative or Monad to automatically get an instance of the respective superclasses? And the generalization for any superclass/subclass? Would be great... If not why so? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160429/11f70dab/attachment-0001.html> ------------------------------ Message: 3 Date: Fri, 29 Apr 2016 11:23:23 +0200 From: D?niel Arat? <exitcons...@gmail.com> To: 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: <cahvkd2jhbowygjxenqz+6lg6dtm5d-w_jnfk1m4sui_edlm...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Applicative is actually a *sub*class of Functor. :) > Hi, well aware it's trivial so I'll be terse: do we have?: >> fmap = <*> . pure That's right. You have to wrap the "<*>" in parantheses though. > So we could write for example >> liftA2 f fa fb = f <$> fa <*> fb > this way?: >> liftA2 f fa fb = pure f <*> fa <*> fb <*> You don't need the last "<*>", but other than that yeah, that's exactly right. > Incidentally, do we have?: >> liftA == liftM == fmap Correct. The Prelude defines liftM in terms of do notation though for reasons that escape me. But it's basically just fmap. Daniel ------------------------------ Message: 4 Date: Fri, 29 Apr 2016 11:31:56 +0200 From: D?niel Arat? <exitcons...@gmail.com> To: 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: <cahvkd2l7uq6+k5sj+t84cdw1oy7vrrj-ecf7ppjahcmtvwe...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 > Oh, and by the way, is it enough then to create an instance of Applicative > or Monad to automatically get an instance of the respective superclasses? > And the generalization for any superclass/subclass? Would be great... If > not why so? I think the latest GHC should be able to give you the superclass instances like you said. Before GHC 7.10 the class hierarchy was a bit disjointed: a Monad was not necessarily an Applicative (even though it should be). https://wiki.haskell.org/Functor-Applicative-Monad_Proposal Daniel ------------------------------ Message: 5 Date: Fri, 29 Apr 2016 12:16:57 +0200 From: Silent Leaf <silent.le...@gmail.com> To: 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: <cagfccjnx0nghab2dw4rzsftb3q4cwup9hqafckjyrf1_dca...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Yes true, subclass, mixed up the terms. ^^ Ah true, I heard about this D?niel. But then it would be generalized to all classes, or just those three ones? Anyway, trying the same with Applicative and its *sub*class Monad: > pure = return > (<*>) :: Monad m => m (a -> b) -> m a -> m b > mf <*> ma = let mg = mf >>= \f -> return (return . f) in mg >>= \g -> (ma >>= g) As: > f :: a -> b > return . f :: Monad m => a -> m b > mg :: Monad m => m (a -> m b) Is there an easier solution? It's easy enough, but not as trivial as for Applicative => Functor. Which leads me to one question I have for a long now. I haven't found my answer, but perhaps did I not search at the right place... Why do we write constraints like that: > Functor f => (a -> b) -> f a -> f b or: > Functor f => Applicative f I'm far from an expert in Math, but I'm used to reading (=>) as an implication, but maybe is it completely different? At any rate, if it were an implication, i'd expect it to be written for example (Applicative f => Functor f), to denote maybe that anything being an Applicative should also be a functor (everything in the first is (= must be, in declarative terms) in the second). I mean if we see a class as a set of types (can we btw?) then if A(pplicative) is superclass of M(onad), A is a superset of M, because (m in M) => (m in A), hence the direction of the implication arrow, Monad => Applicative. Same thing for types of function (and other values), eg (a -> b => Num a), the type of the function would imply some constraint, which would therefore imply that no type that doesn't respect the implied term (constraint) can pretend to be "part" of the type of the function/value. Maybe I'm misinterpreting the purpose or meaning, but I still wonder what is the actual meaning then of those (=>) arrows as they don't *seem* to be implications in the mathematical meaning I'd intuitively imagine. Thanks both for your answers! Le vendredi 29 avril 2016, D?niel Arat? <exitcons...@gmail.com> a ?crit : >> Oh, and by the way, is it enough then to create an instance of Applicative >> or Monad to automatically get an instance of the respective superclasses? >> And the generalization for any superclass/subclass? Would be great... If >> not why so? > > I think the latest GHC should be able to give you the superclass > instances like you said. Before GHC 7.10 the class hierarchy was a bit > disjointed: a Monad was not necessarily an Applicative (even though it > should be). > https://wiki.haskell.org/Functor-Applicative-Monad_Proposal > > Daniel > _______________________________________________ > Beginners mailing list > Beginners@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/20160429/47318688/attachment-0001.html> ------------------------------ Message: 6 Date: Fri, 29 Apr 2016 12:18:15 +0200 From: Silent Leaf <silent.le...@gmail.com> To: 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: <CAGFccjN8TtYBF6gk5D_ibajg+=wagwepo5ftfneeyk533ap...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Lol, well I said "thanks both" but actually there's only one person. Don't mind me I'm drunk. Le vendredi 29 avril 2016, Silent Leaf <silent.le...@gmail.com> a ?crit : > Yes true, subclass, mixed up the terms. ^^ > > Ah true, I heard about this D?niel. But then it would be generalized to all classes, or just those three ones? > > Anyway, trying the same with Applicative and its *sub*class Monad: >> pure = return >> (<*>) :: Monad m => m (a -> b) -> m a -> m b >> mf <*> ma = > let mg = mf >>= \f -> return (return . f) > in mg >>= \g -> (ma >>= g) > As: >> f :: a -> b >> return . f :: Monad m => a -> m b >> mg :: Monad m => m (a -> m b) > > Is there an easier solution? It's easy enough, but not as trivial as for Applicative => Functor. > > Which leads me to one question I have for a long now. I haven't found my answer, but perhaps did I not search at the right place... > > Why do we write constraints like that: >> Functor f => (a -> b) -> f a -> f b > or: >> Functor f => Applicative f > I'm far from an expert in Math, but I'm used to reading (=>) as an implication, but maybe is it completely different? At any rate, if it were an implication, i'd expect it to be written for example (Applicative f => Functor f), to denote maybe that anything being an Applicative should also be a functor (everything in the first is (= must be, in declarative terms) in the second). I mean if we see a class as a set of types (can we btw?) then if A(pplicative) is superclass of M(onad), A is a superset of M, because (m in M) => (m in A), hence the direction of the implication arrow, Monad => Applicative. > > Same thing for types of function (and other values), eg (a -> b => Num a), the type of the function would imply some constraint, which would therefore imply that no type that doesn't respect the implied term (constraint) can pretend to be "part" of the type of the function/value. > > Maybe I'm misinterpreting the purpose or meaning, but I still wonder what is the actual meaning then of those (=>) arrows as they don't *seem* to be implications in the mathematical meaning I'd intuitively imagine. > > Thanks both for your answers! > > Le vendredi 29 avril 2016, D?niel Arat? <exitcons...@gmail.com> a ?crit : >>> Oh, and by the way, is it enough then to create an instance of Applicative >>> or Monad to automatically get an instance of the respective superclasses? >>> And the generalization for any superclass/subclass? Would be great... If >>> not why so? >> >> I think the latest GHC should be able to give you the superclass >> instances like you said. Before GHC 7.10 the class hierarchy was a bit >> disjointed: a Monad was not necessarily an Applicative (even though it >> should be). >> https://wiki.haskell.org/Functor-Applicative-Monad_Proposal >> >> Daniel >> _______________________________________________ >> Beginners mailing list >> Beginners@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/20160429/fb6d8692/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 94, Issue 29 *****************************************