a universal printer for Haskell?

Bernard James POPE bjpop@cs.mu.OZ.AU
Wed, 20 Feb 2002 17:46:01 +1100 (EST)


Hi all,

This thread started with the consideration of a means (hack?) to implement
a generic printer in Haskell. It has moved to the bigger issue of 
Meta programming, in particular reflection. I think this is a topic worthy
of consideration, and something we don't seem to talk much about in 
these groups.

> Ashley Yakeley writes:
> What I would hate to see is widespread use of reflection in general 
> programs. It rather seems to miss the point of Haskell's type system.

I think the point of Haskell's type system varies depending on who you ask.
The rules may be fixed to a certain degree in Haskell 98, but future
versions of the language are free to change them. 

Meta programming is made more difficult when you have a strong static type
system, no doubt. But is that a problem of meta programming or of the
type system? This is a matter of opinion.
Systems such as Meta ML [1], show that the two can be made compatible. 
I must admit that I haven't used Meta ML, so I'm not in a position to
evaluate it, although it does make for some interesting research.

My point is that there are some things that can't easily be expressed
in current Haskell (like generic printing) that are useful and 
might be aided by meta-programming technology. The interesting question
is can it be done in a way that preserves whatever we want from the type
system: safety, security, efficiency, error detection ...

> And I don't want other people peeking inside my types at run-time.

There are numerous ways to provide security for your data types.
You can specifically request that they not be made visible to the meta
facility, or you can use a module system to grant access to
the implementation of data only in certain modules. It does not
have to be program wide. The scheme I suggested for generic printing
was not as safe as you might like, but it was intended to be simple
and easy to implement, and there is some merit in that I think.

Cheers,
Bernie.