Skip to content

Type does not carry through seq. #8

@indicee-michald

Description

@indicee-michald

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions