@@ -6,6 +6,7 @@ import Control.Comonad (class Comonad)
6
6
import Control.Extend (class Extend )
7
7
import Control.Lazy as CL
8
8
9
+ import Data.Functor.Invariant (class Invariant , imapF )
9
10
import Data.HeytingAlgebra (implies , ff , tt )
10
11
import Data.Monoid (class Monoid , mempty )
11
12
@@ -19,61 +20,64 @@ import Data.Monoid (class Monoid, mempty)
19
20
-- | type class instances.
20
21
-- |
21
22
-- | `Lazy` values can be evaluated by using the `force` function.
22
- foreign import data Lazy :: * -> *
23
+ foreign import data Lazy :: Type -> Type
23
24
24
25
-- | Defer a computation, creating a `Lazy` value.
25
26
foreign import defer :: forall a . (Unit -> a ) -> Lazy a
26
27
27
28
-- | Force evaluation of a `Lazy` value.
28
29
foreign import force :: forall a . Lazy a -> a
29
30
30
- instance semiringLazy :: ( Semiring a ) => Semiring (Lazy a ) where
31
+ instance semiringLazy :: Semiring a => Semiring (Lazy a ) where
31
32
add a b = defer \_ -> force a + force b
32
33
zero = defer \_ -> zero
33
34
mul a b = defer \_ -> force a * force b
34
35
one = defer \_ -> one
35
36
36
- instance ringLazy :: ( Ring a ) => Ring (Lazy a ) where
37
+ instance ringLazy :: Ring a => Ring (Lazy a ) where
37
38
sub a b = defer \_ -> force a - force b
38
39
39
- instance commutativeRingLazy :: ( CommutativeRing a ) => CommutativeRing (Lazy a )
40
+ instance commutativeRingLazy :: CommutativeRing a => CommutativeRing (Lazy a )
40
41
41
- instance euclideanRingLazy :: ( EuclideanRing a ) => EuclideanRing (Lazy a ) where
42
+ instance euclideanRingLazy :: EuclideanRing a => EuclideanRing (Lazy a ) where
42
43
degree = degree <<< force
43
44
div a b = defer \_ -> force a / force b
44
45
mod a b = defer \_ -> force a `mod` force b
45
46
46
- instance fieldLazy :: ( Field a ) => Field (Lazy a )
47
+ instance fieldLazy :: Field a => Field (Lazy a )
47
48
48
- instance eqLazy :: ( Eq a ) => Eq (Lazy a ) where
49
+ instance eqLazy :: Eq a => Eq (Lazy a ) where
49
50
eq x y = (force x) == (force y)
50
51
51
- instance ordLazy :: ( Ord a ) => Ord (Lazy a ) where
52
+ instance ordLazy :: Ord a => Ord (Lazy a ) where
52
53
compare x y = compare (force x) (force y)
53
54
54
- instance boundedLazy :: ( Bounded a ) => Bounded (Lazy a ) where
55
+ instance boundedLazy :: Bounded a => Bounded (Lazy a ) where
55
56
top = defer \_ -> top
56
57
bottom = defer \_ -> bottom
57
58
58
- instance semigroupLazy :: ( Semigroup a ) => Semigroup (Lazy a ) where
59
+ instance semigroupLazy :: Semigroup a => Semigroup (Lazy a ) where
59
60
append a b = defer \_ -> force a <> force b
60
61
61
- instance monoidLazy :: ( Monoid a ) => Monoid (Lazy a ) where
62
+ instance monoidLazy :: Monoid a => Monoid (Lazy a ) where
62
63
mempty = defer \_ -> mempty
63
64
64
- instance heytingAlgebraLazy :: ( HeytingAlgebra a ) => HeytingAlgebra (Lazy a ) where
65
+ instance heytingAlgebraLazy :: HeytingAlgebra a => HeytingAlgebra (Lazy a ) where
65
66
ff = defer \_ -> ff
66
67
tt = defer \_ -> tt
67
68
implies a b = implies <$> a <*> b
68
69
conj a b = conj <$> a <*> b
69
70
disj a b = disj <$> a <*> b
70
71
not a = not <$> a
71
72
72
- instance booleanAlgebraLazy :: ( BooleanAlgebra a ) => BooleanAlgebra (Lazy a )
73
+ instance booleanAlgebraLazy :: BooleanAlgebra a => BooleanAlgebra (Lazy a )
73
74
74
75
instance functorLazy :: Functor Lazy where
75
76
map f l = defer \_ -> f (force l)
76
77
78
+ instance invariantLazy :: Invariant Lazy where
79
+ imap = imapF
80
+
77
81
instance applyLazy :: Apply Lazy where
78
82
apply f x = defer \_ -> force f (force x)
79
83
@@ -91,7 +95,7 @@ instance extendLazy :: Extend Lazy where
91
95
instance comonadLazy :: Comonad Lazy where
92
96
extract = force
93
97
94
- instance showLazy :: ( Show a ) => Show (Lazy a ) where
98
+ instance showLazy :: Show a => Show (Lazy a ) where
95
99
show x = " (defer \\ _ -> " <> show (force x) <> " )"
96
100
97
101
instance lazyLazy :: CL.Lazy (Lazy a ) where
0 commit comments