Cardinality-0.1: Data/NeverEmptyList.hs
{-
Copyright (C) 2010 Andrejs Sisojevs <andrejs.sisojevs@nextmail.ru>
All rights reserved.
For license and copyright information, see the file COPYRIGHT
-}
--------------------------------------------------------------------------
--------------------------------------------------------------------------
module Data.NeverEmptyList where
data NeverEmptyList a = NEL a [a]
-- | @neverEmptyList2List (NEL h t) = h:t@
nel2List :: NeverEmptyList a -> [a]
nel2List (NEL h t) = h:t
-- | @list2NeverEmptyList [] = Nothing@
--
-- @list2NeverEmptyList (h:t) = Just (NEL h t)@
list2nel :: [a] -> Maybe (NeverEmptyList a)
list2nel [] = Nothing
list2nel (h:t) = Just (NEL h t)
nelSingleton :: a -> NeverEmptyList a
nelSingleton a = NEL a []