1
1
module Data.Const where
2
2
3
- import Control.Applicative (class Applicative , pure )
4
- import Control.Apply (class Apply )
5
- import Control.Bind (class Bind )
6
- import Control.Semigroupoid (class Semigroupoid )
7
-
8
- import Data.BooleanAlgebra (class BooleanAlgebra )
9
- import Data.Bounded (class Bounded , bottom , top )
10
- import Data.CommutativeRing (class CommutativeRing )
11
- import Data.Eq (class Eq , (==))
12
- import Data.EuclideanRing (class EuclideanRing , mod , degree , (/))
13
- import Data.Field (class Field )
3
+ import Prelude
4
+
14
5
import Data.Foldable (class Foldable )
15
- import Data.Functor (class Functor )
16
6
import Data.Functor.Contravariant (class Contravariant )
17
7
import Data.Functor.Invariant (class Invariant , imapF )
18
- import Data.HeytingAlgebra (class HeytingAlgebra , not , implies , tt , ff , (&&), (||))
19
8
import Data.Monoid (class Monoid , mempty )
20
- import Data.Ord (class Ord , compare )
21
- import Data.Ring (class Ring , (-))
22
- import Data.Semigroup (class Semigroup , (<>))
23
- import Data.Semiring (class Semiring , one , zero , (+), (*))
24
- import Data.Show (class Show , show )
9
+ import Data.Newtype (class Newtype )
25
10
import Data.Traversable (class Traversable )
26
11
27
12
-- | The `Const` type constructor, which wraps its first type argument
@@ -33,59 +18,37 @@ import Data.Traversable (class Traversable)
33
18
-- | ignoring return values.
34
19
newtype Const a b = Const a
35
20
36
- -- | Unwrap a value of type `Const a b`.
37
- getConst :: forall a b . Const a b -> a
38
- getConst (Const x) = x
21
+ derive instance newtypeConst :: Newtype (Const a b ) _
39
22
40
- instance eqConst :: Eq a => Eq (Const a b ) where
41
- eq (Const x) (Const y) = x == y
23
+ derive newtype instance eqConst :: Eq a => Eq (Const a b )
42
24
43
- instance ordConst :: Ord a => Ord (Const a b ) where
44
- compare (Const x) (Const y) = compare x y
25
+ derive newtype instance ordConst :: Ord a => Ord (Const a b )
45
26
46
- instance boundedConst :: Bounded a => Bounded (Const a b ) where
47
- top = Const top
48
- bottom = Const bottom
27
+ derive newtype instance boundedConst :: Bounded a => Bounded (Const a b )
49
28
50
29
instance showConst :: Show a => Show (Const a b ) where
51
30
show (Const x) = " (Const " <> show x <> " )"
52
31
53
32
instance semigroupoidConst :: Semigroupoid Const where
54
33
compose _ (Const x) = Const x
55
34
56
- instance semigroupConst :: Semigroup a => Semigroup (Const a b ) where
57
- append (Const x) (Const y) = Const (x <> y)
35
+ derive newtype instance semigroupConst :: Semigroup a => Semigroup (Const a b )
58
36
59
- instance monoidConst :: Monoid a => Monoid (Const a b ) where
60
- mempty = Const mempty
37
+ derive newtype instance monoidConst :: Monoid a => Monoid (Const a b )
61
38
62
- instance semiringConst :: Semiring a => Semiring (Const a b ) where
63
- add (Const x) (Const y) = Const (x + y)
64
- zero = Const zero
65
- mul (Const x) (Const y) = Const (x * y)
66
- one = Const one
39
+ derive newtype instance semiringConst :: Semiring a => Semiring (Const a b )
67
40
68
- instance ringConst :: Ring a => Ring (Const a b ) where
69
- sub (Const x) (Const y) = Const (x - y)
41
+ derive newtype instance ringConst :: Ring a => Ring (Const a b )
70
42
71
- instance euclideanRingConst :: EuclideanRing a => EuclideanRing (Const a b ) where
72
- degree (Const x) = degree x
73
- div (Const x) (Const y) = Const (x / y)
74
- mod (Const x) (Const y) = Const (x `mod` y)
43
+ derive newtype instance euclideanRingConst :: EuclideanRing a => EuclideanRing (Const a b )
75
44
76
- instance commutativeRingConst :: CommutativeRing a => CommutativeRing (Const a b )
45
+ derive newtype instance commutativeRingConst :: CommutativeRing a => CommutativeRing (Const a b )
77
46
78
- instance fieldConst :: Field a => Field (Const a b )
47
+ derive newtype instance fieldConst :: Field a => Field (Const a b )
79
48
80
- instance heytingAlgebraConst :: HeytingAlgebra a => HeytingAlgebra (Const a b ) where
81
- ff = Const ff
82
- tt = Const tt
83
- implies (Const x) (Const y) = Const (x `implies` y)
84
- conj (Const x) (Const y) = Const (x && y)
85
- disj (Const x) (Const y) = Const (x || y)
86
- not (Const x) = Const (not x)
49
+ derive newtype instance heytingAlgebraConst :: HeytingAlgebra a => HeytingAlgebra (Const a b )
87
50
88
- instance booleanAlgebraConst :: BooleanAlgebra a => BooleanAlgebra (Const a b )
51
+ derive newtype instance booleanAlgebraConst :: BooleanAlgebra a => BooleanAlgebra (Const a b )
89
52
90
53
instance functorConst :: Functor (Const a ) where
91
54
map _ (Const x) = Const x
0 commit comments