[Haskell-beginners] applicative style

Williams, Wes(AWF) wewilliams at paypal.com
Fri Aug 28 17:12:29 UTC 2015


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


<interactive>:54:1:

    Non type-variable argument in the constraint: Fractional (Maybe r)

    (Use FlexibleContexts to permit this)

    When checking that 'it' has the inferred type

      it :: forall a r.

            (Fractional (Maybe r), Num a, Num (Int -> Maybe a -> r)) =>

            Maybe r -> Maybe r

All the parts work individually. If use let and assign the parts to x and y it also works.

E.g. This works
let x = Just $ foldl (+) estimates
Let y = Just . fromIntegral $ length estimates
(/) <$> x <*> y

I clearly do not understand exactly how these work. :-)

Thanks for any help,
-wes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150828/52bd710e/attachment.html>


More information about the Beginners mailing list