|
|
|
|
|
by loup-vaillant
4367 days ago
|
|
Generics generally simplify code, you know. Plus, generic code tend to make guarantees non-generic code cannot. Picture this function: foo :: (a -> b) -> (b -> c) -> (a -> c)
What does it do?As you can see this function takes 2 arguments, which appears to be functions. It also returns a function. The argument and return type of these functions are unknown, so you can't manipulate them. You can just pass them around directly. This puts really tight constraints on your code. So, assuming nothing fancy happens, there is only one correct body of code for this type signature: foo f g = \x -> g (f x)
In other words, function composition.--- Generic functions have more guarantees than non-generic functions. Therefore, you are more likely to know what a generic function is actually doing. |
|