{-# LANGUAGE FlexibleInstances #-}

import Control.Monad.Writer

type MyMonad = Maybe

class ToMyMonad a where
  compile :: a -> MyMonad ()

instance ToMyMonad (MyMonad ()) where
  compile = id

instance (Foldable f, ToMyMonad m) => ToMyMonad (f m) where
  compile = foldM (const compile) ()

fail1 = compile (Just ())

-- src/Lib.hs:16:9-25: error: …
--     • Overlapping instances for ToMyMonad (Maybe ())
--         arising from a use of ‘compile’
--       Matching instances:
--         instance (Foldable f, ToMyMonad m) => ToMyMonad (f m)
--           -- Defined at /home/thblt/Documents/Code/Haskell-Playground/src/Lib.hs:13:10
--         instance ToMyMonad (MyMonad ())
--           -- Defined at /home/thblt/Documents/Code/Haskell-Playground/src/Lib.hs:10:10
--     • In the expression: compile (Just ())
--       In an equation for ‘fail1’: fail1 = compile (Just ())
--    |
-- Compilation failed.