Skip to content

Instantly share code, notes, and snippets.

@becojo
Created January 11, 2015 17:26
Show Gist options
  • Select an option

  • Save becojo/385d31be4074ac0e279e to your computer and use it in GitHub Desktop.

Select an option

Save becojo/385d31be4074ac0e279e to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances, IncoherentInstances #-}
import Control.Monad
data Id a = Id a
deriving Show
instance Monad Id where
(Id x) >>= f = f x
return = Id
class Zero a where
isZero :: a -> Bool
isZero _ = False
instance Zero (Id (Id a)) where
isZero _ = False
instance Zero (Id a) where
isZero _ = True
class Number a where
numValue :: a -> Int
instance Number (Id a) where
numValue x
| isZero x = 0
| otherwise = numValue $ join x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment