-- | Functions

module Data.Function where

import Prelude

-- | (*) `on` f = \x y -> f x * f y.
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
on b -> b -> c
f a -> b
g a
x a
y = b -> b -> c
f (a -> b
g a
x) (a -> b
g a
y)

-- | The \"f\" is for \"Fay\", not \"Functor\" ;)
fmap :: (a -> b) -> Fay a -> Fay b
fmap :: (a -> b) -> Fay a -> Fay b
fmap a -> b
f Fay a
a = Fay a
a Fay a -> Ptr (a -> Fay b) -> Fay b
forall a b. Ptr (Fay a) -> Ptr (a -> Fay b) -> Fay b
>>= b -> Fay b
forall a. a -> Fay a
return (b -> Fay b) -> (a -> b) -> Ptr (a -> Fay b)
forall t1 t t2. (t1 -> t) -> (t2 -> t1) -> t2 -> t
. a -> b
f

-- | See '<*>'.
ap :: Fay (a -> b) -> Fay a -> Fay b
ap :: Fay (a -> b) -> Fay a -> Fay b
ap Fay (a -> b)
m Fay a
g = do a -> b
f <- Fay (a -> b)
m
            a
x <- Fay a
g
            b -> Fay b
forall a. a -> Fay a
return (a -> b
f a
x)

-- | A la Control.Applicative.
(<*>) :: Fay (a -> b) -> Fay a -> Fay b
<*> :: Fay (a -> b) -> Fay a -> Fay b
(<*>) = Fay (a -> b) -> Fay a -> Fay b
forall a b. Fay (a -> b) -> Fay a -> Fay b
ap