|
1 | 1 | module Data.Identity where |
2 | 2 |
|
| 3 | +import Prelude |
| 4 | + |
3 | 5 | import Control.Alt (class Alt) |
4 | | -import Control.Applicative (class Applicative) |
5 | | -import Control.Apply (class Apply) |
6 | | -import Control.Bind (class Bind) |
7 | 6 | import Control.Comonad (class Comonad) |
8 | 7 | import Control.Extend (class Extend) |
9 | | -import Control.Monad (class Monad) |
10 | | - |
11 | | -import Data.BooleanAlgebra (class BooleanAlgebra) |
12 | | -import Data.Bounded (class Bounded, bottom, top) |
13 | | -import Data.CommutativeRing (class CommutativeRing) |
14 | | -import Data.Eq (class Eq, (==)) |
15 | | -import Data.EuclideanRing (class EuclideanRing, degree, mod, (/)) |
16 | | -import Data.Field (class Field) |
| 8 | + |
17 | 9 | import Data.Foldable (class Foldable) |
18 | | -import Data.Functor (class Functor, (<$>)) |
19 | 10 | import Data.Functor.Invariant (class Invariant, imapF) |
20 | | -import Data.HeytingAlgebra (class HeytingAlgebra, not, implies, ff, tt, (||), (&&)) |
21 | | -import Data.Monoid (class Monoid, mempty) |
22 | | -import Data.Ord (class Ord, compare) |
23 | | -import Data.Ring (class Ring, (-)) |
24 | | -import Data.Semigroup (class Semigroup, (<>)) |
25 | | -import Data.Semiring (class Semiring, one, zero, (+), (*)) |
26 | | -import Data.Show (class Show, show) |
| 11 | +import Data.Monoid (class Monoid) |
| 12 | +import Data.Newtype (class Newtype) |
27 | 13 | import Data.Traversable (class Traversable) |
28 | 14 |
|
29 | 15 | newtype Identity a = Identity a |
30 | 16 |
|
31 | | -runIdentity :: forall a. Identity a -> a |
32 | | -runIdentity (Identity x) = x |
| 17 | +derive instance newtypeIdentity :: Newtype (Identity a) _ |
33 | 18 |
|
34 | | -instance eqIdentity :: Eq a => Eq (Identity a) where |
35 | | - eq (Identity x) (Identity y) = x == y |
| 19 | +derive newtype instance eqIdentity :: Eq a => Eq (Identity a) |
36 | 20 |
|
37 | | -instance ordIdentity :: Ord a => Ord (Identity a) where |
38 | | - compare (Identity x) (Identity y) = compare x y |
| 21 | +derive newtype instance ordIdentity :: Ord a => Ord (Identity a) |
39 | 22 |
|
40 | | -instance boundedIdentity :: Bounded a => Bounded (Identity a) where |
41 | | - top = Identity top |
42 | | - bottom = Identity bottom |
| 23 | +derive newtype instance boundedIdentity :: Bounded a => Bounded (Identity a) |
43 | 24 |
|
44 | | -instance heytingAlgebraIdentity :: HeytingAlgebra a => HeytingAlgebra (Identity a) where |
45 | | - ff = Identity ff |
46 | | - tt = Identity tt |
47 | | - implies (Identity x) (Identity y) = Identity (x `implies` y) |
48 | | - conj (Identity x) (Identity y) = Identity (x && y) |
49 | | - disj (Identity x) (Identity y) = Identity (x || y) |
50 | | - not (Identity x) = Identity (not x) |
| 25 | +derive newtype instance heytingAlgebraIdentity :: HeytingAlgebra a => HeytingAlgebra (Identity a) |
51 | 26 |
|
52 | | -instance booleanAlgebraIdentity :: BooleanAlgebra a => BooleanAlgebra (Identity a) where |
| 27 | +derive newtype instance booleanAlgebraIdentity :: BooleanAlgebra a => BooleanAlgebra (Identity a) |
53 | 28 |
|
54 | | -instance semigroupIdenity :: Semigroup a => Semigroup (Identity a) where |
55 | | - append (Identity x) (Identity y) = Identity (x <> y) |
| 29 | +derive newtype instance semigroupIdenity :: Semigroup a => Semigroup (Identity a) |
56 | 30 |
|
57 | | -instance monoidIdentity :: Monoid a => Monoid (Identity a) where |
58 | | - mempty = Identity mempty |
| 31 | +derive newtype instance monoidIdentity :: Monoid a => Monoid (Identity a) |
59 | 32 |
|
60 | | -instance semiringIdentity :: Semiring a => Semiring (Identity a) where |
61 | | - add (Identity x) (Identity y) = Identity (x + y) |
62 | | - zero = Identity zero |
63 | | - mul (Identity x) (Identity y) = Identity (x * y) |
64 | | - one = Identity one |
| 33 | +derive newtype instance semiringIdentity :: Semiring a => Semiring (Identity a) |
65 | 34 |
|
66 | | -instance euclideanRingIdentity :: EuclideanRing a => EuclideanRing (Identity a) where |
67 | | - degree (Identity x) = degree x |
68 | | - mod (Identity x) (Identity y) = Identity (x `mod` y) |
69 | | - div (Identity x) (Identity y) = Identity (x / y) |
| 35 | +derive newtype instance euclideanRingIdentity :: EuclideanRing a => EuclideanRing (Identity a) |
70 | 36 |
|
71 | | -instance ringIdentity :: Ring a => Ring (Identity a) where |
72 | | - sub (Identity x) (Identity y) = Identity (x - y) |
| 37 | +derive newtype instance ringIdentity :: Ring a => Ring (Identity a) |
73 | 38 |
|
74 | | -instance commutativeRingIdentity :: CommutativeRing a => CommutativeRing (Identity a) |
| 39 | +derive newtype instance commutativeRingIdentity :: CommutativeRing a => CommutativeRing (Identity a) |
75 | 40 |
|
76 | | -instance fieldIdentity :: Field a => Field (Identity a) |
| 41 | +derive newtype instance fieldIdentity :: Field a => Field (Identity a) |
77 | 42 |
|
78 | 43 | instance showIdentity :: Show a => Show (Identity a) where |
79 | 44 | show (Identity x) = "(Identity " <> show x <> ")" |
|
0 commit comments