Created
October 6, 2019 03:43
-
-
Save jfischoff/bbd8926c73062f2e625f30cef82b8736 to your computer and use it in GitHub Desktop.
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
-- I think this is a a monoid. Basically it is used to either mappend to a value or replace the value | |
data Lastoid a = Replace a | Mappend a | Nope | |
instance Semigroup a => Semigroup (Lastoid a) where | |
x <> y = case (x, y) of | |
(r@Replace {}, _ ) -> r | |
(Mappend a , Replace b) -> Replace $ a <> b | |
(Mappend a , Mappend b) -> Mappend $ a <> b | |
(Nope , x ) -> x | |
instance Monoid a => Monoid (Lastoid a) where | |
mempty = Nope | |
mappend = (<>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment