[Haskell-beginners] Functions as Applicatives

Olumide 50295 at web.de
Mon Aug 22 23:20:26 UTC 2016


What exactly is f x (g x)? is it (f x)(g x)?? ... Looks like two numbers 
to me e.g. 42 43 ... This can only make sense if they are arguments to 
another binary function which I don't see. Or is there something I'm 
missing?

- Olumide


On 22/08/16 22:14, Rein Henrichs wrote:
> 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
> <mailto: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 <mailto:Beginners at haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


More information about the Beginners mailing list