Persuant to my previous question, I have made some progress, but there is something odd going on.
Suppose we want to implement the following algorithm, which is a little simpler than the original problem:
The user types the name of a file as input. Haskell then puts the text "it works" to that file. I tried this:
import System.IO
let openFileWrite name = openFile name WriteMode
h :: IO Handle
h <- fmap openFileWrite getLine -- you need to type in a file name
This looks wrong, because h presumably needs to be a fixed Handle. Being an IO Handle seems to imply it is mutable. Haskell doesn't complain, though.