Created
September 10, 2012 16:21
-
-
Save anonymous/3691872 to your computer and use it in GitHub Desktop.
Example of crazy Num
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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