Re: [Haskell-cafe] Haskell-Cafe Digest, Vol 145, Issue 41

Thanks for your reply, Tom. That last expression doesn’t seem to have the correct type: Prelude Control.Applicative> let l1 = \x f -> pure f <*> x Prelude Control.Applicative> :t l1 l1 :: Applicative f => f a -> (a -> b) -> f b Prelude Control.Applicative> let l2 = \x f -> fmap f x Prelude Control.Applicative> :t l2 l2 :: Functor f => f a -> (a -> b) -> f b Prelude Control.Applicative> let l3 = \x f -> ($ x) <*> pure f Prelude Control.Applicative> :t l3 l3 :: a1 -> a -> (a1 -> a -> b) -> b Is there a typo? Thanks, -db On Sep 29, 2015, at 9:08 AM, haskell-cafe-request@haskell.org wrote:
Message: 2 Date: Tue, 29 Sep 2015 16:40:38 +0100 From: Tom Ellis
To: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Question, re: Typeclassopedia Ex. 4.2.1 Message-ID: <20150929154037.GS14111@weber> Content-Type: text/plain; charset=us-ascii On Tue, Sep 29, 2015 at 07:48:05AM -0700, David Banas wrote:
pure (flip ($)) <*> x <*> pure f = (interchange) pure (flip ($)) <*> pure ($ f) <*> x = (homomorphism)
For one thing, this step doesn't look right. <*> does not associate that way.
It's probably worth at least putting each expression into ghci to check they have the same time
Prelude> import Control.Applicative Prelude Control.Applicative> let l = \x f -> pure (flip ($)) <*> x <*> pure f Prelude Control.Applicative> :t l l :: Applicative f => f a -> (a -> b) -> f b Prelude Control.Applicative> let l2 = \x f -> pure (flip ($)) <*> pure ($ f) <*> x Prelude Control.Applicative> :t l2 l2 :: Applicative f => f (((a -> b1) -> b1) -> b) -> a -> f b
I imagine you're probably going to want to go via ($ x) rather than ($ f), and possibly use that 'pure f <*> x = fmap f x = ($ x) <*> pure f'.
Tom
participants (1)
-
David Banas