-- $Id: NEListShow.hs,v 1.2 2019/09/26 02:30:53 leavens Exp leavens $
module NEListShow where
import NonEmptyList
toNEL :: [a] -> NonEmptyList a
toNEL [] = error "argument to toNEL must not be empty"
toNEL [e] = (Sing e)
toNEL (e:es) = if null es then (Sing e) else (e :# (toNEL es))
toList :: NonEmptyList a -> [a]
toList (Sing x) = x:[]
toList (e :# es) = e : (toList es)
instance (Show a) => Show (NonEmptyList a) where
show (Sing x) = "toNEL [" ++ (show x) ++ "]"
show (x :# xs) = "toNEL [" ++ (show x) ++ ", " ++ (showNERest xs) ++ "]"
where showNERest (Sing y) = show y
showNERest (y :# ys) = (show y) ++ ", " ++ (showNERest ys)