{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module OAlg.Data.Canonical
(
Embeddable(..), Projectible(..)
)
where
import OAlg.Data.Boolean.Definition
class Embeddable a b where
inj :: a -> b
instance (Embeddable a a', Embeddable b b') => Embeddable (a,b) (a',b') where
inj :: (a, b) -> (a', b')
inj (a
a,b
b) = (forall a b. Embeddable a b => a -> b
inj a
a,forall a b. Embeddable a b => a -> b
inj b
b)
instance (Embeddable a a', Embeddable b b', Embeddable c c')
=> Embeddable (a,b,c) (a',b',c') where
inj :: (a, b, c) -> (a', b', c')
inj (a
a,b
b,c
c) = (forall a b. Embeddable a b => a -> b
inj a
a,forall a b. Embeddable a b => a -> b
inj b
b,forall a b. Embeddable a b => a -> b
inj c
c)
class Projectible a b where
prj :: b -> a
instance (Projectible a a', Projectible b b') => Projectible (a,b) (a',b') where
prj :: (a', b') -> (a, b)
prj (a'
a',b'
b') = (forall a b. Projectible a b => b -> a
prj a'
a',forall a b. Projectible a b => b -> a
prj b'
b')
instance (Projectible a a', Projectible b b', Projectible c c')
=> Projectible (a,b,c) (a',b',c') where
prj :: (a', b', c') -> (a, b, c)
prj (a'
a',b'
b',c'
c') = (forall a b. Projectible a b => b -> a
prj a'
a',forall a b. Projectible a b => b -> a
prj b'
b',forall a b. Projectible a b => b -> a
prj c'
c')
instance Boolean b => Embeddable Bool b where
inj :: Bool -> b
inj Bool
True = forall b. Boolean b => b
true
inj Bool
False = forall b. Boolean b => b
false