
using IORefs, one can construct linked lists in Haskell that resemble one's used in imperative C programming.
eg, the following toy code creates a chain of 1000 linked records.
import IOExts
data Record= RecordNil | Record String Int Chain type Chain = IORef Record
main=makeChain [1..1000]
makeChain::[Int]->IO Chain makeChain []=newIORef RecordNil makeChain (a:as)=makeChain as>>= \chain-> newIORef (Record "data" a chain)
such structures will be garbage-collected "automatically", right?
Yes.
in general terms, please comment on how well GHC supports code that uses such structures.
It should work fine.
now, to turn makeChain into a "lazy producer" requires adding an IO to the type of Chain, yielding
type Chain=IO (IORef Record)
please comment on how well GHC would tend to support such a type.
I'm not sure exactly what you mean by "support" in this context, but I'm not aware of any known bugs that would impact your use of the above type. Cheers, Simon