Skip to content

Instantly share code, notes, and snippets.

@jfischoff
Created October 6, 2019 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfischoff/bbd8926c73062f2e625f30cef82b8736 to your computer and use it in GitHub Desktop.
Save jfischoff/bbd8926c73062f2e625f30cef82b8736 to your computer and use it in GitHub Desktop.
-- 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