Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Newtype Lists
{-# LANGUAGE TupleSections #-}
newtype NonEmpty a = NonEmpty { getNonEmpty :: (a, List a) }
newtype List a = List { getList :: Maybe (NonEmpty a) }
nil :: List a
nil = List Nothing
cons :: a -> List a -> List a
cons a =
List . fmap (NonEmpty . (a,) . uncurry cons . getNonEmpty) . getList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.