【发布时间】:2015-11-18 06:25:45
【问题描述】:
我敢肯定,超级简单,但我似乎找不到答案。我调用了一个返回Maybe x 的函数,我想查看x。如何从我的Just x 回复中提取x?
seeMyVal :: IO ()
seeMyVal = do
if getVal == Nothing
then do
putStrLn "Nothing to see here"
else do
putStrLn getVal -- what do I have to change in this line?
getVal :: (Maybe String)
getVal = Just "Yes, I'm real!"
这会引发错误:
Couldn't match type ‘Maybe String’ with ‘[Char]’
Expected type: String
Actual type: Maybe String
In the first argument of ‘putStrLn’, namely ‘getVal’
In a stmt of a 'do' block: putStrLn getVal
【问题讨论】: