
15 Dec
2008
15 Dec
'08
5:45 p.m.
Jeff C. Britton wrote:
do nums <- askForNumbers; map sqrt nums
ERROR - Type error in final generator *** Term : map sqrt nums *** Type : [Integer] *** Does not match : IO a
Here (map sqrt nums) has type [Integer], so you cannot use it in a do expression for IO. Instead, you have to write something which produces an IO action.
do nums <- askForNumbers; printList nums -- works fine
Here, (printList nums) has type IO (), so it fits into the do expression and everything is fine. If you want to print the list of square roots, you have to say so: do nums <- askForNumbers; printList (map sqrt nums) Tillmann