[Haskell-cafe] Eq Type Class: Overloading (==)
Robert Dockins
robdockins at fastmail.fm
Sun Sep 18 19:15:43 EDT 2005
On Sunday 18 September 2005 07:59 am, Tom Hawkins wrote:
> Aaron Denney wrote:
> > On 2005-09-17, Jason Dagit <dagit at eecs.oregonstate.edu> wrote:
> >>A link to supertyping can be found here:
> >>http://repetae.net/john/recent/out/supertyping.html
> >>
> >>After reading that, I wonder why it's not implemented.
> >
> > Not enough people calling for it.
> >
> >>It seems like a wonderfully useful idea.
> >
> > It is. It would be terribly useful for those trying to prototype a
> > new Prelude, and clean up the mathematical structures.
>
> I like the idea of supertyping, but wouldn't that only allow you to
> alter identifiers that were already classified? What about functions in
> the Prelude that don't belong to a type class?
>
> For instance, I have a datatype that needs an append-like operation, yet
> it appears (++) is reserved only for lists.
>
> I recently switched to Haskell from OCaml because I thought type classes
> may solve one of my problems. I'm building an embedded language, which
> has a lot of the basic operations. In OCaml I was forced to invent all
> sort of obscure operator names for the embedded language so as not to
> collide with the standard library.
>
> But with Haskell's Num class, I have been able to reuse (+), (-), and
> (*). However, (==) and (++) are still sticking points. My general
> impression of Haskell is good, though it seems you're somewhat locked-in
> by how the upper levels of the class hierarchy are defined in the
> Prelude, or when the Prelude does not type class generic operator names
> such as (++).
>
> Again, I just stared programming Haskell. Please let me know if I'm
> missing something.
One possible solution for DSLs is to import the Prelude qualified, or with a
hiding clause. That allows you to redefine most of the symbols in the
Prelude, but still use the Prelude ones if needed. (==) is still a little
special because the Prelude (==) is used for some desugaring steps.
More information about the Haskell-Cafe
mailing list