Last active
August 2, 2018 03:14
-
-
Save Solonarv/bc57d7545344d27eb41c870d31c3ebb9 to your computer and use it in GitHub Desktop.
Silly instances.
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
{-# language LambdaCase #-} | |
-- Note: this is just the GF(2) field. | |
instance Num Bool where | |
(+) = (/=) -- XOR | |
(*) = (&&) | |
abs = id | |
signum = id | |
fromInteger = (/= 0) . (`mod` 2) | |
negate = id | |
(-) = (/=) | |
instance Real Bool where | |
toRational = \case True -> 1; False -> 0 | |
instance Integral Bool where | |
quotRem = (,) -- whatever | |
toInteger = \case True -> 1; False -> 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment