mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
Set 5a Ex 2: allow [Char] in addition to String
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user