git.iko.soy/purescript-literals
on main help sign in
Add show instances
commit7b2ae20f77c67b7e419a92fdd0dc7a09b447b18e authorJan Vincent Liwanag <jvliwanag@gmail.com> dateTue 3 Mar 2020, 17:49 (7 years ago) parentfbd7ba9
3 files changed+22
src/Literals/Literal.purs+2 src/Literals/Undefined.purs+2 test/Main.purs+18
src/Literals/Literal.purs+2
@@ -8,6 +8,8 @@ foreign import data Literal :: Type -> Symbol -> Type
88
99instance literalEq :: Eq (Literal typ sym) where
1010 eq _ _ = true
11+instance literalShow :: Show typ => Show (Literal typ sym) where
12+ show a = "(Literal " <> (show $ toValue a) <> ")"
1113
1214toValue :: ∀ s a. Literal a s -> a
1315toValue = unsafeCoerce
src/Literals/Undefined.purs+2
@@ -8,3 +8,5 @@ foreign import undefined :: Undefined
88
99instance undefinedEq :: Eq Undefined where
1010 eq _ _ = true
11+instance undefinedShow :: Show Undefined where
12+ show _ = "Undefined"
test/Main.purs+18
@@ -35,3 +35,21 @@ main = do
3535 -- Eq instance
3636 assertTrue $ undefined == undefined
3737 assertTrue $ (stringLit :: StringLit "foo") == (stringLit :: StringLit "foo")
38+
39+ -- Show instance
40+ assertEqual
41+ { actual: show (stringLit :: StringLit "foo")
42+ , expected: "(Literal \"foo\")"
43+ }
44+ assertEqual
45+ { actual: show (numberLit :: NumberLit "8.0")
46+ , expected: "(Literal 8.0)"
47+ }
48+ assertEqual
49+ { actual: show (intLit :: IntLit "8")
50+ , expected: "(Literal 8)"
51+ }
52+ assertEqual
53+ { actual: show undefined
54+ , expected: "Undefined"
55+ }