[Template-haskell] Release

Manuel M T Chakravarty chak@cse.unsw.edu.au
Mon, 26 May 2003 13:29:50 +1000 (EST)


"Simon Peyton-Jones" <simonpj@microsoft.com> wrote,

> | > > * Use a naming scheme for the functions that avoids having
> | > >   to suffix some with "E" or "D" and some not.  Example: we
> | > >   have "cond", but "letE".  Better *uniformly* use a single
> | > >   suffix for all functions of the same class; eg, "condExp"
> | > >   and "letExp" (or "condE" and "letE" if you desperately
> | > >   want to save letters).
> 
> I'm sorry that I didn't respond to this at the time.  I agree with the
> first sentence, but I had not absorbed the full glory of making every
> single constructor three or four characters longer. Like Tim, I don't
> think this is a good plan.  We don't say JustMaybe and NothingMabye.
> Instead, we just choose constructor names that don't clash within a
> particular module.  (Between unrelated modules, we can rely on qualified
> names etc.)

The Maybe example does not get to the point of the problem.
The Maybe module defines one datatype.  THSyntax defines
many.  One problem is that constructors of some of these
data types clash.  For examples both Exp and Pat have
variables and literals.  Hence, we must disambiguate on a
datatype per datatype basis.  Disambiguating only the names
that clash using an ad-hoc scheme is not user-friendly IMHO,
as it requires the user to know which constructors clash to
reason about whether a name will use an ad-hoc scheme for
disambiguation.

The other reason that the Maybe example doesn't work is
because every half-baked Haskell programmer knows Maybe and
its constructors, as you need it all the time.  THSyntax is
a module that many people will only use occasionally and it
is much more complex.  So, few people will be able to
memorise a complex nameing scheme with many exceptions.

> My suggestion for resolving the occasional clash (and there were only a
> handful) would be to change the constructor name.  For example, we have
> a let form in Exp and in Stmt.  Let's just give one a different name.

That's exactly what I don't like.  It is nice and easy for
whoever knows the module inside out and a pain for everybody
else.

> I would like to see the type 'Typ' change to 'Type', though!

I agree with that.

Andre Pang <ozone@vergenet.net> wrote,

> IMHO, if a choice is to be made between shorter, possibly more cryptic 
> names vs longer but more descriptive names, I'll nearly always prefer 
> the route of having a longer, more descriptive name.  It makes reading 
> code that much easier, and if you're getting tired of typing out a 
> longer name, this is an area where the text editor should help you.  
> (e.g. M-/ in emacs).  Now that I've said that ...

Exactly, what I think.

> I think Manuel's main objection to the old naming scheme was the 
> inconsistency that some constructors were tagged with the type and some 
> weren't, so that there was "Let" and "LetS" instead of, e.g. "LetExp" 
> and "LetStmt".

Yes.

> Perhaps think a good compromise would be to explicitly tag each 
> constructor with the data type, but instead of using a three-letter 
> suffix for Exp, Dec, Pat, Typ, Stmt, use a one-letter suffix (E, D, P, 
> T, S).  From what I've seen, it looks like those five types are the 
> "big ones" which are used a lot, and having only five one-letter 
> abbreviations makes remembering what they're for manageable.

That would be fine by me.

> I'd also remove the "Lit" suffix from the Lit type completely, so 
> instead of CharLit, StringLit etc, it would revert back to Char & 
> String -- it's completely unambiguous what those constructors represent.

Ok.

> Otherwise, I think for the other constructors, leave them as their 
> current long name, as Ian has edited it -- leaving out their suffix 
> them would make them too obtuse.

I think if some datatypes use one letter suffixes, *all*
should do it.  The number one rule about naming conventions
is 

  ** no exceptions **

As long as there are exceptions, it is going to be a pain to
all but expert users.  (A pity only that it's the expert
users who decide the naming scheme...)

Cheers,
Manuel