Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2012 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3691872 to your computer and use it in GitHub Desktop.
Save anonymous/3691872 to your computer and use it in GitHub Desktop.
Example of crazy Num
data Val = Val Int deriving( Show, Eq )
instance Num Val where
(Val a) + (Val b) = Val $ max a b
(Val a) * (Val b) = Val $ a + b
abs a = a
signum _ = (Val 0)
fromInteger = Val . fromInteger
test1 :: Val -> Bool
test1 a = abs a * signum a == a
val1 :: Val
val1 = fromIntegral 1
val2 :: Val
val2 = fromIntegral 2
test2 = val1 + val1 == val2
main = do
print $ test1 (Val 2)
print $ test1 (Val (-3))
print $ test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment