overloaded num types, but not string types?

Hal Daume III hdaume@ISI.EDU
Wed, 24 Jul 2002 11:29:43 -0700 (PDT)


I was wondering if anyone's thought of overloading string literals in the
same way that numeric literals are overloaded.  I know that I tend to use
PackedStrings for almost everything, primarly due to the RegExp stuff and
efficiency.  This means my code is littered with "unpackPS" and
"packString", as in

   ... if foo == packString "bar" ...

or

   ... if unpackPS foo == "bar" ...

I was wondering if someone might consider overloading Strings,
too.  Something like:

class StringLiteral s where
    fromString :: String -> s
    toString :: s -> String -- not necessary, really

then literals in haskell source could be converted from

   ... "foo" ...

to

   ... (fromString "foo") ...

we'd have instances like

instance StringLiteral String where fromString = id
instance StringLiteral PackedString where fromString = packString
...etc...

if not something in ghc, perhaps this might find its way into drift???

 - hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume