[Haskell] why don't we have const Ptrs?

David Roundy droundy at abridgegame.org
Thu Nov 3 18:35:55 EST 2005

On Wed, Nov 02, 2005 at 04:27:03PM +0100, Daan Leijen wrote:
> Hi David,


> One way of dealing with constant pointer is to introduce (yet another)
> phantom type variable 'r' to pointers:
> And we can derive the "const" attribute too:
>  data FooPtr r = FooPtr String (Ptr r Foo)

This is indeed very cool (and much better than I was imagining), but it
seems like there may still be one problem.

It seems to me that a bad person could escape the "constness" feature using
the RULES pragma.  So if all I knew was that hsstrcat had signature

> strcat :: Ptr Write CChar -> Ptr r CChar -> IO ()

then I wouldn't have a guarantee that strcat isn't specialized for
writeable Ptrs, in which case it might have the result of modifying a
pointer when I don't want it to.  Admittedly, this isn't a likely scenario,
but when I have the typechecker check something, I'd like it to give me a
guarantee, with the usual caveat that certain "unsafe" functions aren't
called.  Does the RULES pragma fall in that "unsafe" category?
David Roundy

More information about the Haskell mailing list