# What does `Forky (a -> b) means in type declaration?

This is from some exercise:

``````(<*>) :: Forky (a -> b) -> Forky a -> Forky b
``````

where Forky is defined as

``````data Forky a = Tip a | Branch (Forky a) (Forky a)
deriving (Eq, Show)
``````

Usually, I see `(a -> b)` as a function in the type declaration. But what does `Forky (a -> b)` means?

`a -> b` is a type like any other. Substituting it into the `Forky` declaration means that the first argument to your `<*>` operator will be either a `Tip f` (where `f :: a -> b`) or a `Branch` consisting of two `Forky (a -> b)`. `Forky (a -> b)` is just like a `Forky Int`, except instead of containing integers at the leaves, it contains functions.

`a -> b` is still a function type; here, the type constructor `Forky` is applied to it to get another type. Since `Forky a` is basically a type of binary trees containing `a` values, `Forky (a -> b)` is a tree containing functions.

Note the similarities:

``````data Forky a = Tip  a | Branch (Forky a) (Forky a)
data Tree  a = Leaf a | Node   (Tree  a) (Tree  a)
``````

This is a list of three functions

``````funcs :: [Int -> Int]
funcs = [ abs, \x -> 2*x+1, (`mod` 16) ]
``````

Here's a function that maybe returns a function:

``````adder :: Int -> Maybe (Int -> Int)
``````applyMay :: Maybe (a -> a) -> a -> a