{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Data.List.Cons
( List
, pattern Nil
, pattern Cons
, nil
, cons
, uncons
, singleton
, head
, tail
) where
import Prelude hiding (head,tail)
type List = ([])
{-# COMPLETE Nil, Cons #-}
pattern Nil :: List a
pattern $bNil :: forall a. List a
$mNil :: forall {r} {a}. List a -> ((# #) -> r) -> ((# #) -> r) -> r
Nil = []
pattern Cons :: a -> List a -> List a
pattern $bCons :: forall a. a -> List a -> List a
$mCons :: forall {r} {a}. List a -> (a -> List a -> r) -> ((# #) -> r) -> r
Cons x xs <- (uncons -> Just (x, xs))
where Cons = a -> List a -> List a
forall a. a -> List a -> List a
cons
nil :: List a
{-# INLINABLE nil #-}
nil :: forall a. List a
nil = []
cons :: a -> List a -> List a
{-# INLINABLE cons #-}
cons :: forall a. a -> List a -> List a
cons = (:)
uncons :: List a -> Maybe (a, List a)
{-# INLINABLE uncons #-}
uncons :: forall a. List a -> Maybe (a, List a)
uncons [] = Maybe (a, [a])
forall a. Maybe a
Nothing
uncons (a
x:[a]
xs) = (a, [a]) -> Maybe (a, [a])
forall a. a -> Maybe a
Just (a
x, [a]
xs)
head :: List a -> Maybe a
{-# INLINABLE head #-}
head :: forall a. List a -> Maybe a
head List a
Nil = Maybe a
forall a. Maybe a
Nothing
head (Cons a
x List a
_) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
tail :: List a -> Maybe (List a)
{-# INLINABLE tail #-}
tail :: forall a. List a -> Maybe (List a)
tail List a
Nil = Maybe (List a)
forall a. Maybe a
Nothing
tail (Cons a
_ List a
xs) = List a -> Maybe (List a)
forall a. a -> Maybe a
Just List a
xs
singleton :: a -> List a
{-# INLINE singleton #-}
singleton :: forall a. a -> List a
singleton = (a -> [a] -> [a]
forall a. a -> List a -> List a
:[])