File tree 2 files changed +18
-4
lines changed 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -9,14 +9,15 @@ class Inject a b where
9
9
inj :: a -> b
10
10
prj :: b -> Maybe a
11
11
12
- instance injectLeft :: Inject a (Either a b ) where
12
+ instance injectReflexive :: Inject a a where
13
+ inj = identity
14
+ prj = Just
15
+
16
+ else instance injectLeft :: Inject a (Either a b ) where
13
17
inj = Left
14
18
prj = either Just (const Nothing )
15
19
16
20
else instance injectRight :: Inject a b => Inject a (Either c b ) where
17
21
inj = Right <<< inj
18
22
prj = either (const Nothing ) prj
19
23
20
- else instance injectReflexive :: Inject a a where
21
- inj = identity
22
- prj = Just
Original file line number Diff line number Diff line change @@ -26,6 +26,19 @@ main = do
26
26
{ actual: inj 100 :: MySum
27
27
, expected: in3 100
28
28
}
29
+ log " Test injection with the injectReflexive instance"
30
+ assertEqual
31
+ let
32
+ x = inj 100 :: MySum
33
+ in
34
+ { actual: inj x :: MySum
35
+ , expected: x
36
+ }
37
+ log " Test that injection picks the left-most option"
38
+ assertEqual
39
+ { actual: inj 100 :: Either3 Int Int Int
40
+ , expected: in1 100
41
+ }
29
42
log " Test projection"
30
43
assertEqual
31
44
{ actual: prj (in1 true :: MySum )
You can’t perform that action at this time.
0 commit comments