haskell - Why doesn't `putStrLn getLine` work? -
i'm complete newbie on haskell. haskell script ghci,
prelude> let = putstrln getline makes error this.
<interactive>:1:17: couldn't match expected type `string' against inferred type `io string' in first argument of `putstrln', namely `getline' in expression: putstrln getline in definition of `a': = putstrln getline prelude> why doesn't work , how can print input stdin?
putstrln :: string -> io () getline :: io string the types not match. getline io action, , putstrln takes plain string.
what need bind line inside io monad in order pass putstrln. following equivalent:
a = line <- getline putstrln line = getline >>= \line -> putstrln line = getline >>= putstrln
Comments
Post a Comment