[Haskell-cafe] Type Directed Name Resolution

John Lask jvlask at hotmail.com
Thu Nov 11 03:34:16 EST 2010


On 11/11/2010 5:21 PM, Ketil Malde wrote:
> "Richard O'Keefe"<ok at cs.otago.ac.nz>  writes:
>
>>> it is often desirable to have the same field names
>>> for many records in the same module.
>

very much so, this is currently possible, with the restriction that
the field names must have the same type modulo the record it is 
selecting on.

what is disirable is that this restriction be lifted.

>> I'm not sure that it is desirable to have "many records in the
>> same module" in the first place.
>

this should really be a choice of the programmer.

> One possibility might be to allow mulitple module definitions in the
> same file, making it easier to wrap each record in its own module
> without running into a Java-like forest of files.
>

a module represents a compilation unit which happens to be a file, in 
haskell it also represents a name space and a means for control of that 
namespace. Compilation units and name space management are orthoganal 
issues although obviously connected. SML for example manages the name 
space with Functors and does not explicitly name the compilation units, 
haskell names the compilation units i.e. modules, but I have had some 
thoughts along the same lines, myself, more on this later ..


discussion of the haskell record system and syntax has a long history, 
just a quick search ...

http://www.mail-archive.com/haskell@haskell.org/msg17725.html
http://www.haskell.org/pipermail/haskell-prime/2006-March/000836.html
http://www.mail-archive.com/haskell@haskell.org/msg13394.html
http://www.mail-archive.com/haskell@haskell.org/msg20516.html

in 2003

http://research.microsoft.com/en-us/um/people/simonpj/Haskell/records.html

I quote

"Haskell lacks a serious record system. (The existing mechanism for 
named fields in data types was always seen as a stop-gap measure.) At 
the 1999 Haskell Workshop, Mark Jones and Simon Peyton Jones proposed a 
more fully-fledged record system, closely modelled on the TRex system 
implemented in Hugs. But Simon never got around to implementing it in 
GHC. Why not? Mainly because the implementation cost turned out to be 
relatively high."

.. in the intervening years we have GADTS, type families, associated 
types tec ... but with respect to records what has changed ?


In my mind, the feature that I most wish for, and what haskell lacks is 
the ability to manage the module name space with respect to record label 
names. Yes, I often want to define a record with the same label name at 
a different type.

many languages have a construct "with <record>" which "unqualifies" the 
names introduced by the record definition, those names being implicitly 
qualified when defined. Haskell label names are implicitly "unqualified".

I have often thought that a minimal extension to Haskell compatible with 
the current record system that could ameliorate the situation would be

	data Foo = Foo { label1 :: Int, label2 :: String } qualified

where such a qualified data declaration would hide labels label1 and 
label2, making the available only as Foo.label1, Foo.label2., etc

where we have a qualified record we should be able to "unqualify" it as

	import data Foo

or rename it

	import data Foo qualified as Bar

which would introduces Bar.label1, Bar.label2

etc.

None of the above is incompatible with the current record system and 
introduces no new keywords. This proposal solely addresses the issue of 
name space management.


> (I've proposed this before, and although I don't remember the specifics,
> ISTR the response being mostly negative.)
>
> -k



More information about the Haskell-Cafe mailing list