[Haskell-beginners] Functions as Applicatives

Rein Henrichs rein.henrichs at gmail.com
Mon Aug 22 21:14:19 UTC 2016


In  f <*> g = \x -> f x (g x), g is the second argument to <*>. The result
of f <*> g is a function that takes an argument (x) and gives f x (g x). So
basically <*> combines the functions f and g in a particular way to give a
new function. In fact, it is the only way to combine them that type checks
(and doesn't use undefined or similar).

On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins <imantc at gmail.com> wrote:

> .. actually, I got fg wrong. Caught it by changing g to (/ ):
>
>
> f::Fractional f => f -> f -> f
> f = (+)
>
> g::Fractional g => g -> g
> g a = a / 2
>
> h::Fractional h => h -> h
> h = (* 10)
>
>
> fg::Fractional a =>     a -> a -> a
> fg = f <$> g
> {-  fg a b = (a / 2) + b
>     fg a = \b -> (a / 2) + b
> -}
>
> fgh::Fractional a =>  a -> a
> fgh = fg <*> h
> {-  fgh a = fg a (a * 10)
>     fgh = \a -> fg a (a * 10)
> -}
>
>> _______________________________________________
> Beginners mailing list
> Beginners at 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/20160822/d00370f2/attachment.html>


More information about the Beginners mailing list