Skip to content

Instantly share code, notes, and snippets.

@jdegoes
Created October 27, 2014 18:53
Show Gist options
  • Save jdegoes/7d5314aea4a63a7b6383 to your computer and use it in GitHub Desktop.
Save jdegoes/7d5314aea4a63a7b6383 to your computer and use it in GitHub Desktop.
Lunchtime experiment with booleans
-- 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
@jdegoes
Copy link
Author

jdegoes commented Oct 28, 2014

Lol. That's me, perpetually reinventing ancient findings in computer science... since 1990 or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment