Just learning how to instance Comonad on Non-Empty List
| module Nel where | |
| import Control.Comonad | |
| infixr 5 :| | |
| data Nel a = a :| [a] | |
| toList :: Nel a -> [a] | |
| toList (a :| as) = a : as | |
| instance Functor Nel where | |
| f `fmap` (x :| xs) = f x :| (f `fmap` xs) | |
| instance Comonad Nel where | |
| extract (a :| _) = a | |
| duplicate nel@(_ :| []) = nel :| [] | |
| duplicate nel@(_ :| (i : t)) = nel :| (toList . duplicate $ (i :| t)) | |
This comment has been minimized.
This comment has been minimized.
instance Show a => Show (Nel a) where
show = show . toListλ> duplicate (1 :| [2,3,4]) -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.