git.iko.soy/purescript-literals
on main help sign in
Add show instances
7b2ae20Jan Vincent Liwanag
src/Literals/Literal.purs+2
@@ -8,6 +8,8 @@ foreign import data Literal :: Type -> Symbol -> Type
8
8
9instance literalEq :: Eq (Literal typ sym) where
9instance literalEq :: Eq (Literal typ sym) where
10 eq _ _ = true
10 eq _ _ = true
11+instance literalShow :: Show typ => Show (Literal typ sym) where
12+ show a = "(Literal " <> (show $ toValue a) <> ")"
11
13
12toValue :: ∀ s a. Literal a s -> a
14toValue :: ∀ s a. Literal a s -> a
13toValue = unsafeCoerce
15toValue = unsafeCoerce
src/Literals/Undefined.purs+2
@@ -8,3 +8,5 @@ foreign import undefined :: Undefined
8
8
9instance undefinedEq :: Eq Undefined where
9instance undefinedEq :: Eq Undefined where
10 eq _ _ = true
10 eq _ _ = true
11+instance undefinedShow :: Show Undefined where
12+ show _ = "Undefined"
test/Main.purs+18
@@ -35,3 +35,21 @@ main = do
35 -- Eq instance
35 -- Eq instance
36 assertTrue $ undefined == undefined
36 assertTrue $ undefined == undefined
37 assertTrue $ (stringLit :: StringLit "foo") == (stringLit :: StringLit "foo")
37 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+ }