This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HeytingAlgebra, Semiring, Ring
- Loading branch information
1 parent
08b57e0
commit 3bd3379
Showing
4 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Data.Generic.Rep.HeytingAlgebra where | ||
|
||
import Prelude | ||
|
||
import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments(..), Product(..), from, to) | ||
import Data.HeytingAlgebra (ff, implies, tt) | ||
|
||
class GenericHeytingAlgebra a where | ||
genericFF' :: a | ||
genericTT' :: a | ||
genericImplies' :: a -> a -> a | ||
genericConj' :: a -> a -> a | ||
genericDisj' :: a -> a -> a | ||
genericNot' :: a -> a | ||
|
||
instance genericHeytingAlgebraNoArguments :: GenericHeytingAlgebra NoArguments where | ||
genericFF' = NoArguments | ||
genericTT' = NoArguments | ||
genericImplies' _ _ = NoArguments | ||
genericConj' _ _ = NoArguments | ||
genericDisj' _ _ = NoArguments | ||
genericNot' _ = NoArguments | ||
|
||
instance genericHeytingAlgebraArgument :: HeytingAlgebra a => GenericHeytingAlgebra (Argument a) where | ||
genericFF' = Argument ff | ||
genericTT' = Argument tt | ||
genericImplies' (Argument x) (Argument y) = Argument (implies x y) | ||
genericConj' (Argument x) (Argument y) = Argument (conj x y) | ||
genericDisj' (Argument x) (Argument y) = Argument (disj x y) | ||
genericNot' (Argument x) = Argument (not x) | ||
|
||
instance genericHeytingAlgebraProduct :: (GenericHeytingAlgebra a, GenericHeytingAlgebra b) => GenericHeytingAlgebra (Product a b) where | ||
genericFF' = Product genericFF' genericFF' | ||
genericTT' = Product genericTT' genericTT' | ||
genericImplies' (Product a1 b1) (Product a2 b2) = Product (genericImplies' a1 a2) (genericImplies' b1 b2) | ||
genericConj' (Product a1 b1) (Product a2 b2) = Product (genericConj' a1 a2) (genericConj' b1 b2) | ||
genericDisj' (Product a1 b1) (Product a2 b2) = Product (genericDisj' a1 a2) (genericDisj' b1 b2) | ||
genericNot' (Product a b) = Product (genericNot' a) (genericNot' b) | ||
|
||
instance genericHeytingAlgebraConstructor :: GenericHeytingAlgebra a => GenericHeytingAlgebra (Constructor name a) where | ||
genericFF' = Constructor genericFF' | ||
genericTT' = Constructor genericTT' | ||
genericImplies' (Constructor a1) (Constructor a2) = Constructor (genericImplies' a1 a2) | ||
genericConj' (Constructor a1) (Constructor a2) = Constructor (genericConj' a1 a2) | ||
genericDisj' (Constructor a1) (Constructor a2) = Constructor (genericDisj' a1 a2) | ||
genericNot' (Constructor a) = Constructor (genericNot' a) | ||
|
||
-- | A `Generic` implementation of the `ff` member from the `HeytingAlgebra` type class. | ||
genericFF :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a | ||
genericFF = to genericFF' | ||
|
||
-- | A `Generic` implementation of the `tt` member from the `HeytingAlgebra` type class. | ||
genericTT :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a | ||
genericTT = to genericTT' | ||
|
||
-- | A `Generic` implementation of the `implies` member from the `HeytingAlgebra` type class. | ||
genericImplies :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a -> a -> a | ||
genericImplies x y = to $ from x `genericImplies'` from y | ||
|
||
-- | A `Generic` implementation of the `conj` member from the `HeytingAlgebra` type class. | ||
genericConj :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a -> a -> a | ||
genericConj x y = to $ from x `genericConj'` from y | ||
|
||
-- | A `Generic` implementation of the `disj` member from the `HeytingAlgebra` type class. | ||
genericDisj :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a -> a -> a | ||
genericDisj x y = to $ from x `genericDisj'` from y | ||
|
||
-- | A `Generic` implementation of the `not` member from the `HeytingAlgebra` type class. | ||
genericNot :: forall a rep. Generic a rep => GenericHeytingAlgebra rep => a -> a | ||
genericNot x = to $ genericNot' (from x) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Data.Generic.Rep.Ring where | ||
|
||
import Prelude | ||
|
||
import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments(..), Product(..), from, to) | ||
|
||
class GenericRing a where | ||
genericSub' :: a -> a -> a | ||
|
||
instance genericRingNoArguments :: GenericRing NoArguments where | ||
genericSub' _ _ = NoArguments | ||
|
||
instance genericRingArgument :: Ring a => GenericRing (Argument a) where | ||
genericSub' (Argument x) (Argument y) = Argument (sub x y) | ||
|
||
instance genericRingProduct :: (GenericRing a, GenericRing b) => GenericRing (Product a b) where | ||
genericSub' (Product a1 b1) (Product a2 b2) = Product (genericSub' a1 a2) (genericSub' b1 b2) | ||
|
||
instance genericRingConstructor :: GenericRing a => GenericRing (Constructor name a) where | ||
genericSub' (Constructor a1) (Constructor a2) = Constructor (genericSub' a1 a2) | ||
|
||
-- | A `Generic` implementation of the `sub` member from the `Ring` type class. | ||
genericSub :: forall a rep. Generic a rep => GenericRing rep => a -> a -> a | ||
genericSub x y = to $ from x `genericSub'` from y |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Data.Generic.Rep.Semiring where | ||
|
||
import Prelude | ||
|
||
import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments(..), Product(..), from, to) | ||
|
||
class GenericSemiring a where | ||
genericAdd' :: a -> a -> a | ||
genericZero' :: a | ||
genericMul' :: a -> a -> a | ||
genericOne' :: a | ||
|
||
instance genericSemiringNoArguments :: GenericSemiring NoArguments where | ||
genericAdd' _ _ = NoArguments | ||
genericZero' = NoArguments | ||
genericMul' _ _ = NoArguments | ||
genericOne' = NoArguments | ||
|
||
instance genericSemiringArgument :: Semiring a => GenericSemiring (Argument a) where | ||
genericAdd' (Argument x) (Argument y) = Argument (add x y) | ||
genericZero' = Argument zero | ||
genericMul' (Argument x) (Argument y) = Argument (mul x y) | ||
genericOne' = Argument one | ||
|
||
instance genericSemiringProduct :: (GenericSemiring a, GenericSemiring b) => GenericSemiring (Product a b) where | ||
genericAdd' (Product a1 b1) (Product a2 b2) = Product (genericAdd' a1 a2) (genericAdd' b1 b2) | ||
genericZero' = Product genericZero' genericZero' | ||
genericMul' (Product a1 b1) (Product a2 b2) = Product (genericMul' a1 a2) (genericMul' b1 b2) | ||
genericOne' = Product genericOne' genericOne' | ||
|
||
instance genericSemiringConstructor :: GenericSemiring a => GenericSemiring (Constructor name a) where | ||
genericAdd' (Constructor a1) (Constructor a2) = Constructor (genericAdd' a1 a2) | ||
genericZero' = Constructor genericZero' | ||
genericMul' (Constructor a1) (Constructor a2) = Constructor (genericMul' a1 a2) | ||
genericOne' = Constructor genericOne' | ||
|
||
-- | A `Generic` implementation of the `zero` member from the `Semiring` type class. | ||
genericZero :: forall a rep. Generic a rep => GenericSemiring rep => a | ||
genericZero = to genericZero' | ||
|
||
-- | A `Generic` implementation of the `one` member from the `Semiring` type class. | ||
genericOne :: forall a rep. Generic a rep => GenericSemiring rep => a | ||
genericOne = to genericOne' | ||
|
||
-- | A `Generic` implementation of the `add` member from the `Semiring` type class. | ||
genericAdd :: forall a rep. Generic a rep => GenericSemiring rep => a -> a -> a | ||
genericAdd x y = to $ from x `genericAdd'` from y | ||
|
||
-- | A `Generic` implementation of the `mul` member from the `Semiring` type class. | ||
genericMul :: forall a rep. Generic a rep => GenericSemiring rep => a -> a -> a | ||
genericMul x y = to $ from x `genericMul'` from y |
This file contains 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