[Haskell-cafe] Call for discussion: OverloadedLists extension

Roman Leshchinskiy rl at cse.unsw.edu.au
Tue Sep 25 10:51:53 CEST 2012

Simon Peyton-Jones wrote:
> | pointer to the actual data somewhere in memory and use that. This is
> | more or less what happens for strings at the moment, even though you
> | have to use rewrite rules to get at the pointer which, in my opinion, is
> | neither ideal nor really necessary. IMO, the "right" design shouldn't
> | rely on rewrite rules. Also, strings give you an Addr# whereas vector
> | supports ByteArray#, too.
> If it's not necessary, I wonder if you have an idea for the "right"
> design?

For strings, we could have something like this:

data StringPtr

stringFromStringPtr :: StringPtr -> Int -> String
unsafeStringPtrToPtr :: StringPtr -> Ptr CChar

class IsString a where
  fromString :: String -> a
  fromStringPtr :: StringPtr -> Int -> a
  fromStringPtr p n = fromString $ stringFromStringPtr p n

"abc" would then desugar to fromStringPtr (address of "abc") 3. Note that
we couldn't just use Ptr CChar instead of StringPtr because stringFromPtr
would only be safe if the data that the pointer references never changes.

It's much trickier for general-purpose arrays. It's also much trickier to
support both Ptr and ByteArray. I'd have to think about how to do that.


More information about the Haskell-Cafe mailing list