[Haskell-cafe] There is no null; Maybe/Option types

Henning Thielemann schlepptop at henning-thielemann.de
Sat Apr 23 17:01:37 CEST 2011


Ketil Malde schrieb:

> Maybe is in a sense easier, as 'Maybe a' and 'a' are different types,
> while there isn't a similarly elegant type distinction between lists
> that may be empty and lists with at least one element.  Maybe is really
> quite brilliant.

type NonEmptyList a = (a, [a])

data NonEmptyList a = NonEmptyList a [a]

I use the second one frequently for quick check testing and especially
for testing on infinite lists. Unfortunately, the Prelude functions like
'cycle' (for input and output) and 'group' (for sublists of the result
list) do not use that type.




More information about the Haskell-Cafe mailing list