Skip to content

Instantly share code, notes, and snippets.

@yihuang
Created August 16, 2012 14:20
Show Gist options
  • Save yihuang/3370453 to your computer and use it in GitHub Desktop.
Save yihuang/3370453 to your computer and use it in GitHub Desktop.
There is an instance for any type class
{-# LANGUAGE GADTs #-}
-- take `Monad` for example
class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b
-- we can define an instance mechanically:
data IsMonad a where
Return :: a -> IsMonad a
Bind :: IsMonad a -> (a -> IsMonad b) -> IsMonad b
instance Monad IsMonad where
return = Return
(>>=) = Bind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment