How Do You Read Types?

There are multiple aspects in that type definition that make it a little harder than most.

(<|) : (a → b) → a → b

First, you need to mention that this is a function that is designed to be used infix. An infix function takes 2 arguments. The first argument is the left argument and in this case it is a function from a to b. The second argument is the right argument and in this case it is a value of type a. The result of the infix application of the arguments is of type b.

Explaining a type signature as above requires that the person already understands the concept of a function and of a higher order function ( a function that takes a function as an argument, or returns a function).

value : a - a value of type a

unary : a -> b - a function that takes a value of type a and evaluates to a value of type b

binary : a -> b -> c - a function that takes two arguments. First is a value of type a, second is a value of type b. The function evaluates to a value of type c

higherOrder : (a -> b) -> a -> b - a binary function that takes an unary function as the first argument and a value of type a as the second and evaluates to a value of type b.

And then you get into currying and partial application where a higher arity function can be reduced to a lower arity function by partial application.

So, binary: a -> b -> c it is actually an unary function that produces an unary function so… binary : a -> (b -> c) . ternary : a -> ( b -> ( c -> d)) , etc.

All this gets confusing fast if you don’t understand the idea of higher order functions.

2 Likes