
Greetings folks. 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? Could someone give an explanation... Thanks for taking time.

On 22-Feb-2002, Cagdas Ozgenc
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
participants (2)
-
Cagdas Ozgenc
-
Fergus Henderson