Re:Grain: A strongly-typed functional programming language f...
by dragonwriter on Tuesday July 31, 2018 @12:55PM
(#17654796)
> A harder problem is errors that cannot be handled by a simpler type system. For example, consider Haskell's head function
Haskell's head function is often pointed to as a wart even given Haskell's type system; the signature really ought to be:
head :: [a] -> Maybe a
With a definition (equivalent to):
head [] = None
head x:xs = Some x
It's absolutely not a good example of a source of errors that can't be dealt with in a type system like Haskell's.
> In order to express constraints such as "list must not be empty" or "number must be higher than 1" or "file must be open, the type system needs to understand the semantics of the values expressed by a type system.
Sure, but you don't have to express those as type constraints to avoid runtime errors when they occur; if you can express the distinction in normal code you can use distinctions of return type.
Haskell's head function is often pointed to as a wart even given Haskell's type system; the signature really ought to be:
With a definition (equivalent to): It's absolutely not a good example of a source of errors that can't be dealt with in a type system like Haskell's.> In order to express constraints such as "list must not be empty" or "number must be higher than 1" or "file must be open, the type system needs to understand the semantics of the values expressed by a type system.
Sure, but you don't have to express those as type constraints to avoid runtime errors when they occur; if you can express the distinction in normal code you can use distinctions of return type.