Xref: utzoo sci.math:4503 comp.lang.misc:1873 Path: utzoo!attcan!uunet!mcvax!ukc!etive!lfcs!db From: db@lfcs.ed.ac.uk (Dave Berry) Newsgroups: sci.math,comp.lang.misc Subject: Re: "Semiabstract" datatypes Message-ID: <774@etive.ed.ac.uk> Date: 13 Sep 88 13:32:50 GMT References: <896@tragicomix.liu.se> Sender: news@etive.ed.ac.uk Reply-To: db@lfcs.ed.ac.uk (Dave Berry) Organization: Laboratory for the Foundations of Computer Science, Edinburgh U Lines: 46 In article <896@tragicomix.liu.se> JWC@IDA.LiU.SE (Jonas Wallgren) writes: >Assume the following declaration (in ML) of an abstract tree type: > > abstype tree=leaf of int|branch of tree*tree > with val tend=leaf > fun tfork l1 l2=branch(l1,l2) > end; > >Everytime a tree is created one is forced to write e.g. > > tfork(tend 1)(tend 2); > >My idea is [...] >Then the example above becomes > > tfork 1 2; I'm not sure what you're asking. You can write this in ML as follows: abstype tree=leaf of int|branch of tree*tree with val tend=leaf fun tfork l1 l2=branch(tend l1,tend l2) end; but then you can't write "tfork(tend 1)(tend 2);" anymore. Do you want to be able to write either tfork(tend 1)(tend 2); or tfork 1 2; with the same definition of tfork? I agree this would be useful. I've sometimes wanted it to abbreviate large ML patterns. > Are there any programming languages supporting such a construction? The nearest I know of is C++, which has the feature that if a function expects an argmuent of type A and receives one of type B, it will convert the argument to type A if it knows how to do so. It can do this iff there is a constructor (C++ usage of the word) for type A that takes an argument of type B. Any other offers? > Is there any algebraic concept or other mathematical structure > suitable for describing such a phenomenon? ----------------------------------------------------------------------------- Dave Berry. db@lfcs.ed.ac.uk