[Haskell-beginners] Type for lists with one or more elements
Frerich Raabe
raabe at froglogic.com
Fri Jun 7 02:27:11 CEST 2013
Hi,
is there an existing (or conventional) way to model lists of one or more
items? I often deal with functions with don't make sense with empty
lists, and the caller already verified that the lists are not empty. So
to avoid getting warnings from ghc, I'd like to have a dedicated type
for this case.
I could do something like
data List a = Singleton a | Cons a (List a)
but before I go ahead I wonder: is there an existing Haskell package for
this? Maybe even with prettier names than what I wrote above, and
convenient functions for transforming from/to plain [] lists? It would
probably be straightforward to write it myself, but because of that, I
suspect that somebody else already did it. :-)
--
Frerich Raabe - raabe at froglogic.com
www.froglogic.com - Multi-Platform GUI Testing
More information about the Beginners
mailing list