then I just need to do a forever loop and use this type data to keep the C internal state.
what's worring me is that I have a sort of internal state but this is not expressed anywhere in the type system...
You can use (StateT <your_type> IO) instead of plain IO in the pipe to pass that data around. There are functions for working with StateT (and other transformer) pipes in Pipes.Lift module: https://hackage.haskell.org/package/pipes-4.1.8/docs/Pipes-Lift.html#g:5 Other than that, having to worry about state kept in the C part of a Haskell program is often a pain in general, unfortunately. Perhaps you could take some hints from https://hackage.haskell.org/package/GPipe for example, but I have no idea if that's going to be of any help.
I get a segfault when I do a big number of coputation ???
The only change is from Pipes.print to Pipes.drain? This is weird, maybe you'd have better luck asking on Pipes mailing list: https://groups.google.com/forum/?fromgroups#!forum/haskell-pipes ( mailto:haskell-pipes@googlegroups.com ) Best regards, Marcin Mrotek