Immutable CStrings

George Russell
Wed, 23 Apr 2003 18:15:37 +0200

How would one implement an CStringLen-style type that
(a) was efficient, in particular could be read and written to Handles
(b) would get automatically deallocated by the Haskell garbage collector,
when Haskell no longer referred to it;
(c) was immutable, so that once created the character data could not
be changed;
(d) consequently had the property that conversion to and from String would
be a pure operation;
(e) could be passed to and from C using the FFI.  (Of course C would need you
to split the length and character data up; the character data would presumably
have type "const char *".)
It would be rather nice to have such a type.