mardi 24 février 2015

Couldn't match type errors in haskell

I literally started learning haskell in the past few hours following this tutorial. I keep getting Couldn't match type error when trying to compile the following code:



module Main where
main = do
let ages = []
putStrLn "Enter child 1"
input <- getLine
-- convert the string to int
let age1 = read input :: Int
ages ++ [age1]
putStrLn "Enter child 2 age"
input <- getLine
-- convert the string to int
let age2 = read input :: Int
ages ++ [age2]
putStr "Age of your first child: "
print age1
putStr "Age of your second child: "
print age2


Here is the error:



Couldn't match type `[]' with `IO'
Expected type: IO Int
Actual type: [Int]
In a stmt of a 'do' block: ages ++ [age1]


I have been searching for several hours trying to understand the issue but have no clue. Why does ages ++ [age2] expects a type IO Int ? and how to resolve this issue?


Aucun commentaire:

Enregistrer un commentaire