[Haskell-beginners] Problems with one of my first examples

Tillmann Rendel rendel at daimi.au.dk
Mon Dec 15 17:45:08 EST 2008

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)


More information about the Beginners mailing list