4 ms·
You're partially right, but function composition features in the type world too. For example, when you say - data Tree a = Leaf a | Branch (Tree a) (Tree a
by sriku 11y ago
You're partially right, but function composition features in the type world too. For example, when you say -
data Tree a = Leaf a | Branch (Tree a) (Tree a)
It looks like you're dealing purely with types, however you've declared two constructors "Leaf" and "Branch" which are, in essence, functions with the following signatures -
Leaf :: a -> Tree a
Branch :: Tree a -> Tree a -> Tree a
Additionally, you have `Branch` being an operation that's closed on trees (i.e. maps trees to trees), which composes nicely.
On top of that, type classes are mechanisms to talk about which functions can be called on which data, hence guiding which functions can be composed with which others.