Set 5a Ex 2: allow [Char] in addition to String

This commit is contained in:
Joel Kaasinen
2021-09-21 13:06:22 +03:00
parent ca1f32aded
commit f00717b794
2 changed files with 6 additions and 0 deletions
+4
View File
@@ -80,6 +80,10 @@ data FieldType = SimpleType String | WeirdType
interpretFieldType (ConT n) = SimpleType $ nameBase n
interpretFieldType (VarT n) = SimpleType $ nameBase n
interpretFieldType (AppT ListT t) =
case interpretFieldType t of
SimpleType s -> SimpleType $ "[" ++ s ++ "]"
_ -> WeirdType
interpretFieldType (AppT t1 t2) =
case (interpretFieldType t1, interpretFieldType t2) of
(SimpleType s1, SimpleType s2) -> SimpleType $ s1 ++ " " ++ s2
+2
View File
@@ -58,7 +58,9 @@ ex2 = $(reifyType "BusTicket") $ \(DataType vars cs) ->
,counterexample " should have a constructor SingleTicket with no fields" $
any (==Constructor "SingleTicket" []) cs
,counterexample " should have a constructor MonthlyTicket with a String field" $
counterexample (show cs) $
any (==Constructor "MonthlyTicket" [SimpleType "String"]) cs
|| any (==Constructor "MonthlyTicket" [SimpleType "[Char]"]) cs
]
word = listOf1 (choose ('a','z'))