[Haskell-beginners] Applicative Composition
Brent Yorgey
byorgey at seas.upenn.edu
Thu Sep 30 21:41:04 EDT 2010
On Fri, Oct 01, 2010 at 01:47:09AM +0200, edgar klerks wrote:
> Hi All,
>
> I was wondering, why there isn't a composition operator for applicative
> functors. Of course it is rather trivial to implement, but it is a useful
> feature:
I think you've answered your own question: it's rather trivial to
implement. If we added every single useful function to the standard
libraries, we'd be up to our necks.
> {-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
> module ApplicativeComposition where
> import Control.Applicative
>
> class (Applicative f) => ApplicativeComposition f where
> (<.>) :: f (b -> c) -> f (a -> b) -> f (a -> c)
>
> instance (Applicative f) => ApplicativeComposition f where
> (<.>) f g = pure (.) <*> f <*> g
>
> Can this be added to later versions of haskell?
You can always make a formal proposal [1], although judging by past
discussions of similar sorts of things I doubt it would be accepted,
for the reasons I wrote above.
Also, why bother making a new ApplicativeComposition type class?
Since you can simply implement (<.>) in terms of existing Applicative
methods the new type class doesn't really add anything.
-Brent
Footnotes:
[1] http://www.haskell.org/haskellwiki/Library_submissions
More information about the Beginners
mailing list