do expression

sashan sashang@ihug.co.nz
Tue, 06 May 2003 00:20:18 +0000


Hi

I'm trying to write a simple program to get user input and execute a 
function based on the input. The program follows:

import IO

main = do putStrLn "1) f1"
           putStrLn "2) f2"
           choice <- getLine
           case choice of
             1 -> do putStrLn "f1"
             2 -> do putStrLn "f2"
             _ -> do putStrLn ""

When compiled with ghc I get the following error:
test.hs:8:
     No instance for (Num String)
     arising from the pattern `2' at test.hs:8
     In a case alternative: 2 -> do putStrLn "f2"
     In the case expression:
	case choice of
	  1 -> do putStrLn "f1"
	  2 -> do putStrLn "f2"
	  _ -> do putStrLn ""


Please can someone explain.

Thanks