I am reading the values ββfrom the console using readLn.
I would like to write a function:
requestValue :: String -> IO a
requestValue s = do
putStrLn $ "Please enter a new value for " ++ s
readLn
Then I could do, for example,
changeAge :: Person -> IO Person
changeAge p = do
age' <- requestValue "age"
return $ p { age = age'}
changeName :: Person -> IO Person
changeName p = do
name' <- requestValue "name"
return $ p { name = name'}
The problem is that reading the String instance requires the string to be in quotation marks. I do not want to type "Fred"in the console to change the name when I really only want to type Fred.
Is there an easy way to do this while maintaining requestValuepolymorphic?
source
share