haskell - IO Char array not usable in place of a String when using liftM -
I have a function that I want to print value. It is not pure because it uses values from some random functions, which I have already determined that they work correctly. My code is
getWord :: [IO four] getWord = getRandomConsonant: getRandomVowel: getRandomConsonant: getRandomConsonant: getRandomVowel: [] main = do liftM putStrLn getWord
I am under the assumption that Lift M
putStrLn
is allowed to print the value of getWord
, but it failed with error Living:
word.hs: 30: 24: `[four] 'could not match the type' IO four 'with the expected type: [string] Actual type: [Io Four] in the second argument of 'LiftM', a Whereas GetWord in an STMT of a 'Do' block: LiftM putStrLn getWord Expression: Do {LiftM putStrLn getWord}
This does not work, there is no way [IO Char]
?
I understand that the object must be "executed" to the IO
in order to get the value, but I could not understand one of the ways to do it. If there is a misunderstanding here, please forgive me, as I have started learning Haskell right now.
be careful: [IO char]
no IO [Char]
If you have something like IO
like return is "Hi"
, you do Can:
(return "hi")> gt; & Gt; = Print
But because your type is [IO char]
, which is a list of IO char
, you have to do something like this :
sequence [(return 'H'), (return 'I')]> gt; <= Print
Comments
Post a Comment