Szymon Ząbkiewicz wrote:
> Hi!
> I'm new to Haskell and FP so i've got some problems. I wrote this code :
> 
> getNr :: Int -> Int
> getNr x = do
>     putStrLn ("enter " ++ x ++ " number:")
>     nr <- getLine
>     return nr
> 
> And when I try to load it to GHCi I get an error (there is also plenty
> of others but they look the same):

There are several problems with this code:

1. You are using (++) to concatenate strings and the value x, which
   is of type Int.  Use 'show' to convert numbers to strings.

2. The result type of getNr is Int, but the body of the function is
   a do expression, which is always a monadic value.  Since you use
   the input/output operations putStrLn and getLine, the type of
   the function must be Int -> IO Int

3. The return value of getLine is a string, but you try to return
   it from the function, which (see 2) has a return value of IO Int.
   Use 'read' to convert the string to an integer value.

HTH,
  Martin

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to