[Haskell-cafe] Re: Debugging partial functions by the rules

Udo Stenzel u.stenzel at web.de
Wed Nov 15 07:57:48 EST 2006


Donald Bruce Stewart wrote:
> So how do we help out the beginners, other than warning about fromJust,
> and providing a useful error message as we can, for when they just go
> ahead and use head anyway?

Kill head and tail right now and provide a safe equivalent?  Either

  uncons :: [a] -> Maybe (a,[a])

which is to be used in conjunction with 'maybe' (or with
fmap/first/second/unfoldr) or

  list :: r -> (a -> [a] -> r) -> [a] -> r

in analogy with 'maybe' and 'either'.  Or combine it with 'foldr' to
form the paramorphism (if I got the terminology right).  Or even better,
don't mention the existence of uncons and encourage people to write list
consumers in terms of 'destroy'.


-Udo
-- 
Sturgeon's Law: Ninety percent of everything is crud.
(Sturgeon was an optimist.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/6ed247ff/attachment.bin


More information about the Haskell-Cafe mailing list