Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Last active August 2, 2018 03:14
Show Gist options
  • Save Solonarv/bc57d7545344d27eb41c870d31c3ebb9 to your computer and use it in GitHub Desktop.
Save Solonarv/bc57d7545344d27eb41c870d31c3ebb9 to your computer and use it in GitHub Desktop.
Silly instances.
{-# 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