Does someone knows what this code does?I know its validating the given year but I didn't really get the idea of the whole process.
tempYear <- getLine
case reads tempYear :: [(Integer, String)] of
[(n, "")] -> do let year = read tempYear :: Int
I guess the case reads
is there to deal with the case in which getLine does not return a proper number. reads
returns a list of possible answers. If the tempYear were to start with a non-digit the empty list would be returned. If there was some other letter or something like that in the string, then the number up to that letter would be n
. But the second value in the tuple would not be the empty string but the unparsed rest of the string.
However, I don't know why he would read an Integer
first and then an Int
. If the two types were equal, n
would also be equal to year
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments