-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
CAL reports a type error in the following, even though the type of r is clear.
test :: [Boolean];
test = readList ["True", "False"];
readList :: Read a => [String] -> [a];
readList xs =
case xs of
[] -> [];
x : rest ->
let
r = read x;
in
r `seq` (r : readList rest);
;
class Read a where
read :: String -> a;
;
instance Read Boolean where
read = readBoolean;
;
readBoolean :: String -> Boolean;
readBoolean !str =
if str == "True" then
True
else if str == "False" then
False
else
error ("readBoolean: can't read '" ++ str ++ "'.");
Equivalent Haskell code:
test :: [Bool]
test = myReadList ["True", "False"]
myReadList :: Read a => [String] -> [a]
myReadList [] = []
myReadList (x:xs) =
let
r = read x
in
r `seq` (r : myReadList xs)
Metadata
Metadata
Assignees
Labels
No labels