Tue, 04 Jan 2011 12:05:37 +0100

From: | torbenm@diku.dk (Torben Ęgidius Mogensen) |

Newsgroups: | comp.compilers |

Date: | Tue, 04 Jan 2011 12:05:37 +0100 |

Organization: | SunSITE.dk - Supporting Open source |

References: | 10-12-040 |

Keywords: | design, storage |

Posted-Date: | 04 Jan 2011 11:22:12 EST |

noitalmost <noitalmost@cox.net> writes:

*> My question is this: Would variant records provide significant value*

*> to a user of my language (given that classes were implemented)?*

You can also reverse the question: Given that you have records and

(tagged) unions (== sum types), will classes provide significant value?

If I had to chose either sum types or classes, my choice will be sum

types -- especially if you have ML-style pattern matching.

For example, syntax trees are much easier to represent using sum types

than using classes.

You can define subtyping without introducing classes:

A record Y is a subtype of a record X if for every field f of type t in

X there is a field f of type t' in Y such that t' is a subtype of t.

A sum type Y is a subtype of a sum type X if for every tag (constructor)

c in Y with type t there is a tag c in X with type t' such that t is a

subtype of t'.

Note the symmetry: Subtypes of a sum have fewer tags and subtypes of a

record have more fields. The empty record can be seen as the top type

in the subtype relation while the empty sum (no possible value) is the

bottom type.

Torben

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.