I have the following function:
get :: Chars -> IO Chars
get cs = do
char <- getChar
let (dats, idx) = (curData cs, curIndex cs)
let (x,y:xs
It's impossible (I lie, there is an extremely unsafe way to cheat your way out of it).
The point is that if any I/O is performed, the behaviour and result of your programme may not depend only on explicit arguments to the used functions, thus that must be declared in the type by having it IO something
.
You use the result of an IO a
action in a pure function by binding the result in main
(or something called from main
) and then applying the pure function, binding the result in a let
,
cs ::Chars
cs = undefined
main = do
chars <- get cs
let result = pureFunction chars
print result
or, if the function you want to apply to chars
has type Chars -> IO b
main = do
chars <- get cs
doSomething chars