Alex Rivera | Logout

Output Integer to stdout in Haskell

Asked 2012-04-21T23:46:30.583
21

I have a simple function like:

nth :: Integer -> Integer

And I try to print it's result as follows:

main = do
    n <- getLine
    result <- nth (read n :: Integer)
    print result

The following error is generated:

Couldn't match expected type `IO t0' with actual type `Integer'
In the return type of a call of `nth'
In a stmt of a 'do' expression:
    result <- nth (read n :: Integer)

Also tried with putStrLn and a lot of other combinations with no luck.
I can't figure it out and I would need some help, being that I don't fully understand how stuff works around these IOs.

Edit
Report

1 Answer

20

nth is a function, not an IO action:

main = do
  n <- getLine
  let result = nth (read n :: Integer)
  print result
answered 2012-04-21T23:55:50.133

Your Answer