[Haskell-beginners] applicative style

Mario Lang mlang at delysid.org
Thu Sep 24 15:41:05 UTC 2015


David Moberg <kaddkaka at gmail.com> writes:

> This mail got stuck in my spam filter because of auth reason.
> Bumping in case someone else who missed it wants to answer.
>
> 2015-08-28 19:12 GMT+02:00 Williams, Wes(AWF) <wewilliams at paypal.com>:
>
>> Hi haskellers,
>>
>> I am trying to understand why I get the following error in learning
>> applicative style.
>>
>> Prelude> let estimates = [5,5,8,8,2,1,5,2]
>>
>> Prelude> (/) <$> Just $ foldl (+) 0 estimates <*> Just . fromIntegral $ length estimates

I think $ is the culprit.  You can not combine $ and <*> and
get what you expect, because $ works on *the whole* expression:

Prelude> (/) <$> Just (foldl (+) 0 estimates) <*> Just (fromIntegral (length estimates))
Just 4.5

Another problem was (.), you actually don't need any function
composition here.

-- 
CYa,
  ⡍⠁⠗⠊⠕
  


More information about the Beginners mailing list