Permalink
Browse files

* Convert booleans to type families

* Fix tryth tables
  • Loading branch information...
1 parent 88defa8 commit 233a51112ab82122fae9599288cf12f8d8d2244c @Shimuuar committed Jun 22, 2010
Showing with 29 additions and 33 deletions.
  1. +29 −33 Types/Boolean.hs
View
@@ -1,16 +1,15 @@
-{-# LANGUAGE TypeFamilies #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE EmptyDataDecls #-}
module Types.Boolean ( True
, False
-- * Boolean operations
- , NotT(..)
+ , Not
, notT
- , AndT(..)
+ , And
, andT
- , OrT(..)
+ , Or
, orT
- , XorT(..)
+ , Xor
, xorT
) where
@@ -25,50 +24,47 @@ instance Show True where show _ = "True"
----------------------------------------------------------------
-- | Negation
-class NotT a where
- type Not a :: *
-notT :: NotT a => a -> Not a
+type family Not a :: *
+
+notT :: a -> Not a
notT _ = undefined
-instance NotT False where type Not False = True
-instance NotT True where type Not True = False
+type instance Not False = True
+type instance Not True = False
----------------------------------------------------------------
-- | And for boolean types
-class AndT a b where
- type And a b :: *
+type family And a b :: *
-andT :: AndT a b => a -> b -> And a b
+andT :: a -> b -> And a b
andT _ _ = undefined
-instance AndT False False where type And False False = False
-instance AndT False True where type And False True = False
-instance AndT True False where type And True False = False
-instance AndT True True where type And True True = True
+type instance And False False = False
+type instance And False True = False
+type instance And True False = False
+type instance And True True = True
----------------------------------------------------------------
-- | Or for boolean types
-class OrT a b where
- type Or a b :: *
+type family Or a b :: *
-orT :: OrT a b => a -> b -> Or a b
+orT :: a -> b -> Or a b
orT _ _ = undefined
-instance OrT False False where type Or False False = False
-instance OrT False True where type Or False True = False
-instance OrT True False where type Or True False = False
-instance OrT True True where type Or True True = True
+type instance Or False False = True
+type instance Or False True = True
+type instance Or True False = True
+type instance Or True True = False
----------------------------------------------------------------
-- | Exlusive or for boolean types
-class XorT a b where
- type Xor a b :: *
+type family Xor a b :: *
-xorT :: XorT a b => a -> b -> Xor a b
+xorT :: a -> b -> Xor a b
xorT _ _ = undefined
-instance XorT False False where type Xor False False = False
-instance XorT False True where type Xor False True = False
-instance XorT True False where type Xor True False = False
-instance XorT True True where type Xor True True = True
+type instance Xor False False = False
+type instance Xor False True = True
+type instance Xor True False = True
+type instance Xor True True = False

0 comments on commit 233a511

Please sign in to comment.