Created
April 2, 2019 05:12
-
-
Save bradparker/75dba2b56a154cf18f4e5128b6d9e135 to your computer and use it in GitHub Desktop.
Newtype Lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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