🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #241

Re: Types as first-class values?

#241
From: Ole Lehrmann Madsen
Date: Thu, 16 Apr 1992 16:42
77 lines
2781 bytes
oscar@cui.unige.ch (Oscar Nierstrasz) writes:

>Can anyone provide any references to programming languages that
>treat types as first-class values?

>....

In BETA a pattern is a first-class value in the sense that a variable
may be assigned a pattern. Such pattern values may be passed around as 
parameters and returned as the result from functions. 

Consider patterns

	T: (# ... #)

with subpatterns

	T1: T (# ... #);
	T2: T (# ... #)

The following is a declaration of two pattern variables

	F1,F2: ## T

F1 and F2 may be assigned pattern T or subpatterns of T.

Ex.

	T1## -> F1##;  { F1 is assigned the pattern T1}
	&F1[] -> R1[]; { a new instance of F1 is created; since the value
			 of F1 is the pattern T1, an instance of  T1 is created}

	T2## -> F2##;
        F2## -> F1##   
	&F1[] -> R1[]; {an instance of T2 is created}

Since a pattern may be used as e.g. a class or a procedure, classes and
procedures may be passed around as arguments and results of functions.

By using pattern variables instead of virtual patterns (procedures)
it is possible to change the methods of an object after it has been created.

Pattern variables are relatively inexpensive in BETA and used for many
purposes. They are of course NOT like Smalltalk metaclasses.

>So, for a type to be first-class:

>1. you must be able to bind it to a variable, pass it around, etc.,

I think this is satisfied.

>2. test whether a value satisfies it (and, if it does, be able to use that
>   value in a type-safe way within the scope of the test),

	At run-time it is possible to test the value of af pattern variable

	F## = T1	true if F## denotes T1

	F## < T1	true if F## denotes a subpattern of T1

	etc.

>3. produce new types from old at run-time by means of type-operators.

	The only type-operators for combining pattern variables into
	new patterns are pattern declarations where pattern variables
	may be used as attributes. This is perhaps not what you want?

I will be happy to supply more information.

Ole Lehrmann Madsen
Computer Science Department
Aarhus University
Ny Munkegade
DK-8000 Aarhus C, DENMARK
Tel.: +45 86 12 71 88 Fax.: +45 86 13 57 25
E-mail: olmadsen@daimi.aau.dk
Technical Details
Message-ID: <1992Apr16.164204.2027@daimi.aau.dk>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!mips!swrinde!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!dkuug!daimi!olm
References: <7597@cui.unige.ch>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!mips!swrinde!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!dkuug!daimi!olm
From: olm@daimi.aau.dk (Ole Lehrmann Madsen)
Newsgroups: comp.lang.misc,comp.lang.functional,comp.object
Subject: Re: Types as first-class values?
Message-ID: <1992Apr16.164204.2027@daimi.aau.dk>
Date: 16 Apr 92 16:42:04 GMT
References: <7597@cui.unige.ch>
Sender: olm@daimi.aau.dk (Ole Lehrmann Madsen)
Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
Lines: 77