Created
October 27, 2014 18:53
-
-
Save jdegoes/7d5314aea4a63a7b6383 to your computer and use it in GitHub Desktop.
Lunchtime experiment with booleans
This file contains hidden or 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
-- booleans as a partition on a set | |
type Bool a = a -> Either a a | |
true' :: forall a. Bool a | |
true' = Right | |
false' :: forall a. Bool a | |
false' = Left | |
not' :: forall a. Bool a -> Bool a | |
not' b = \a -> case b a of | |
Left a -> Right a | |
Right a -> Left a | |
(||) :: forall a b. Bool a -> Bool b -> Bool (Tuple a b) | |
(||) l r = \(Tuple a b) -> case (Tuple (l a) (r b)) of | |
Tuple (Right a) (Right b) -> Right (Tuple a b) | |
Tuple (Left a) (Right b) -> Right (Tuple a b) | |
Tuple (Right a) (Left b) -> Right (Tuple a b) | |
Tuple (Left a) (Left b) -> Left (Tuple a b) | |
(&&) :: forall a b. Bool a -> Bool b -> Bool (Tuple a b) | |
(&&) l r = \(Tuple a b) -> case (Tuple (l a) (r b)) of | |
Tuple (Right a) (Right b) -> Right (Tuple a b) | |
Tuple (Left a) (Right b) -> Left (Tuple a b) | |
Tuple (Right a) (Left b) -> Left (Tuple a b) | |
Tuple (Left a) (Left b) -> Left (Tuple a b) | |
if' :: forall a b. Bool a -> b -> b -> a -> b | |
if' p t f a = case p a of | |
Left a -> f | |
Right a -> t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lol. That's me, perpetually reinventing ancient findings in computer science... since 1990 or so.