Skip to content

Instantly share code, notes, and snippets.

@jchia
Last active May 25, 2018 18:06
Show Gist options
  • Save jchia/316dff3a66366ecf0efcb1aeac82ad11 to your computer and use it in GitHub Desktop.
Save jchia/316dff3a66366ecf0efcb1aeac82ad11 to your computer and use it in GitHub Desktop.
Canonical Monoid instance & UndecidableInstances: Do I really need to turn on UndecidableInstances?
newtype CdRoot a = CdRoot (IO a)
cdRoot :: CdRoot a -> IO a
cdRoot (CdRoot x) = changeWorkingDirectory "/" >> x
instance Semigroup a => Semigroup (CdRoot a) where
CdRoot x <> CdRoot y = CdRoot $ x <> y
-- The constraint ‘Semigroup (CdRoot a)’ is no smaller than the instance head (Use UndecidableInstances to permit this)
instance (Semigroup (CdRoot a), Monoid a) => Monoid (CdRoot a) where
mempty = CdRoot mempty
mappend = (<>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment