[Haskell-cafe] Why Maybe exists if there is Either?

Artyom Kazak yom at artyom.me
Fri Jan 10 01:29:07 UTC 2014


On 01/10/2014 04:17 AM, John Lato wrote:
> I think this is a really important point.  If I may go further, it's 
> arguable that 'type String = [Char]' was a poor decision, and one of 
> the arguments is that it's not possible to make different instances 
> for String and [a] (hence the showsList issue).
Actually, I think it’s an instance of a bigger problem: *newtypes aren’t 
as transparent as they should’ve been*. The very first thing a beginner 
is told about newtypes is that they bear no additional runtime cost at 
all – which, in fact, hasn’t been strictly true until the recent 
introduction of Roles – but the first thing they learn *by theirself* is 
that newtypes are only “free” for the computer, not for the programmer!

Imagine an alternative Prelude in which `String` is a newtype for 
`[Char]` and not a type synonym: you wouldn’t be able to `map` over it 
without deconstructing it first, or `reverse` it, or even compute its 
`length`... And having to type `f (Str s)` instead of `f s` would 
already discourage people enough that most of them would be trying to 
avoid Strings, even if only subconsciously.

General tendency to follow the path of least resistance is probably the 
reason why newtypes aren’t used as often as they should be. Have there 
been any proposals aiming to solve this issue? (A quick search didn’t 
bring up anything, but maybe I was just searching for a wrong thing.)


More information about the Haskell-Cafe mailing list