Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created August 14, 2015 07:41
Show Gist options
  • Save fumieval/7cb288313c802a36740f to your computer and use it in GitHub Desktop.
Save fumieval/7cb288313c802a36740f to your computer and use it in GitHub Desktop.
data Pos a = Rel !a | Abs !a deriving (Show, Read, Eq, Ord, Functor)
instance Num a => Monoid (Pos a) where
mempty = Rel 0
_ `mappend` Abs a = Abs a
Abs a `mappend` Rel b = Abs (a + b)
Rel a `mappend` Rel b = Rel (a + b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment