2 ms·
You can relabel Double with a type alias. Really, adding a newtype gives you a sort of partial equivalent of tagged arguments (requires tags, doesn't permit re
by dllthomas 13y ago
You can relabel Double with a type alias. Really, adding a newtype gives you a sort of partial equivalent of tagged arguments (requires tags, doesn't permit reordering), and might be best practice when there's more semantic content and no clear typical order (eg, you're passing price and quantity to makeOrder, rather than base and exponent to exp). I make a habit of doing this with my C (where a single element struct adds no overhead, much like a Haskell newtype).
- mightybyte 13y agoYeah, type aliases can be really useful for some kinds of type documentation. But they seem a bit on the heavy side for one-off things like the exp and map examples.
- dllthomas 13y agoI agree that it doesn't make sense for exp or map, but not because they are one-off; rather because they are already clear enough that it's not going to add much. For map in particular what are you going to rename? You can name unbound parameters without a newtype: map :: (input -> output) -> [input] -> [output] might add a bit; map :: MapFunction a b -> [a] -> [b] takes more away than it adds I think.