Skip to content

anonymous /crazy.hs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.