Я уверен, что это очень просто, но я не могу найти ответ. Я вызываю функцию, которая возвращает Maybe x
, и хочу увидеть x
. Как мне извлечь x
из моего Just 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