От: | AlexRK | ||
Дата: | 23.01.17 21:21 | ||
Оценка: |
getChar :: IO Char
The return function admits an ordinary value such as a boolean to the realm of I/O actions. What about the other direction? Can we invoke some I/O actions within an ordinary expression? For example, how can we say x + print y in an expression so that y is printed out as the expression evaluates? The answer is that we can't! It is not possible to sneak into the imperative universe while in the midst of purely functional code. Any value `infected' by the imperative world must be tagged as such. A function such as
f :: Int -> Int -> Int
absolutely cannot do any I/O since IO does not appear in the returned type.