
27 Dec
2009
27 Dec
'09
9:03 p.m.
Hi, My purpose is to get data from the keyboard and return a maybe value, saying "nothing" if the data entered is invalid. I get a message "could'nt match expected IO Integer against inferred type maybe integer" on line x<- getdata Why should x be Maybe ? getdatanum is, but getdata is not. Is it possible to write only one function rather than 2 distinct ones ? Thanks for your help, Didier. Here's my code getdata :: IO Integer getdata=do x<-getLine let xn=read x ::Integer return xn getdatanum :: Maybe Integer getdatanum = do x <- getdata {- if x < 5 then do return (Just x) else do return Nothing -} return (Just x)