Re: Curry module system

From: Sebastian Fischer <sebf_at_informatik.uni-kiel.de>
Date: Wed, 01 Mar 2006 14:21:11 +0100

On Feb 27, 2006, at 12:29 Uhr, Claus Reinke wrote:

> but, whatever you do, try to prepare for future change better than
> haskell did.

I see two properties of the Haskell98 system for labeled fields, that
probably prevent an extension to a record system:

1. the data constructor of a Haskell98-style record is accessible:

data Person = Person { name :: String, age :: Int }
isOfFullAge (Person _ age) = age >= 18

2. field selection is expressed as function application:

isOfFullAge person = age person >= 18

We could prepare for future extensions by hiding constructors and
providing a new syntax for field selection:

type Person = { name :: String, age :: Int }
isOfFullAge person = person{age} >= 18

I think curly brackets are quite natural for field selection since
they are already used for updates and restriction. In a first
approach, this could be desugared into the same code that is
generated for Haskell98-style records (without exporting the
constructor). This implementation would still have the restriction,
that field labels are in the global namespace and cannot be reused.
But this restriction could be released by another implementation.

However, expressing field selection as function application
facilitates the implementation of abstract datatypes as records. The
selector functions do not reveal the internal representation of the
record - a special syntax does. For example, we could decide to
change the definition of Person

type Person = { name :: String, dateOfBirth :: Int }
age person = now - dateOfBirth person

and still, the age of a person is obtained by function application.
With a new syntax for field selection, the code of all programs that
select the age of persons needs to be altered. As a consequence, the
implementor of an abstract datatype may still provide *functions* like

name person = person{name}

which is exactly the kind of code that originally should be
eliminated by a system for labeled fields.

Regards,
Sebastian


_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Wed Mar 01 2006 - 16:41:46 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 19 2019 - 07:15:06 CEST