Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safer Handles in Haskell?

I felt a bit insecure when using Haskell Handles. Namely, I'm looking for two features (maybe they are already there and in that case please forgive my ignorance).

  1. When I've obtained a handle (e.g., returned by Network.accept), which is both readable and writable, I wish to convert them into a pair of read-only and write-only handles such that writing to a read-only handle won't type check and vice versa. (Perhaps one can achieve this using phantom types and wraps around IO functions?)
  2. In a concurrent setting, I found that it is possible for multiple threads to write to the same handle, which gives rise to quite nasty consequences. How could one prevent that through the type system (if possible) or at least get notified of such case via thrown exception during run-time?

Any idea is welcome.

like image 937
tfboy Avatar asked Aug 08 '13 20:08

tfboy


1 Answers

It looks like the safer-file-handles library does what you want. The first part is handled pretty clearly. The concurrency-safety appears to be handled by RegionT from the regions library. I haven't used this at all, but it looks like a pretty common approach.

like image 185
Carl Avatar answered Oct 25 '22 12:10

Carl