if -> is a type constructor
Fergus Henderson
fjh@cs.mu.oz.au
Sun, 24 Feb 2002 22:26:18 +1100
On 22-Feb-2002, Cagdas Ozgenc <co19@cornell.edu> wrote:
> If (->) is a type constructor, what does its definition look like, what data
> constructors does it have? How does it differ from other type constructors,
> or maybe it doesn't?
It is an abstract data type.
The representation is implementation-dependent.
The data constructor(s) for (->) are not accessible to programs,
so you can't e.g. pattern-match against them.
Implementations are likely to use a specialized representation for (->).
For example, they might use something similar to the following C structure.
(This is from the Mercury implementation. I hope this example doesn't raise
more questions than it answers ;-)
/*
** A closure is a vector of words containing:
**
** one word pointing to the closure layout structure of the procedure
** one word pointing to the code of the procedure
** one word giving the number of arguments hidden in the closure (N)
** N words representing the N hidden arguments
...
*/
typedef struct MR_Closure_Struct {
MR_Closure_Layout *MR_closure_layout;
MR_Code *MR_closure_code;
MR_Unsigned MR_closure_num_hidden_args;
MR_Word MR_closure_hidden_args[MR_VARIABLE_SIZED];
} MR_Closure;
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.