>f (case xs of (x:_) -> x; [] -> error "whoops")  -- direct style

Yup, this is how I do it... I never use head!

I like to pass failures back up to the level where some kind of sensible 
error message can be generated. In your example the error is no
better than with 'head' - the point is a Nothing can be 'caught' 
outside of an IO monad. 

I would suggest using the type system as I said earlier so:

toNonEmptyList :: [a] -> Maybe (NonEmpty a)
toNonEmptyList (a0:_) = Just (NonEmpty a)
toNonEmptyList _ = Nothing

Then redefine head:

head :: NonEmpty a -> a
head (NonEmpty (a0:_)) = a0


        Keean/
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to