Here is an elaboration for three properties which I think enable replacing flat code by functions without adding cognitive overhead for the person who reads the code:
- Benefits: if type signatures convey a lot of meaning and if such signatures can be trusted, then they may be sufficient. In some cases, you may not need to know more about a function than the fact that it safely converts a value from type A to type B.
- Tooling opportunities: an editor can show type signatures at hand, e.g. on hover or even by inlining them.
- Without it: if the function signature is
Int -> Void
or evenInt -> Int
, you must look at its definition to know what it does.
- Benefits: the only "effect" of functions is what they return. Just by looking at what happens to the return value of a function in the calling code thus allows knowing all the consequences of the function call.
- Tooling opportunities: referential transparency allows replacin