Re: [ats-lang-users] Difference between viewt@ype and viewt@ype+?
Unleashing the potentials of types and templates
Status: Beta
Brought to you by:
ats-hwxi
From: Hongwei Xi <hw...@cs...> - 2010-10-23 12:51:14
|
On Sat, 23 Oct 2010, Andrew Richards wrote: >>On Sat, Oct 23, 2010 at 01:21:35PM +0600, Artyom Shalkhakov wrote: >>> I believe that [absviewtype] is for abstract view types of size of one >>> pointer, whereas [absviewt@ype] is for abstract view types of unknown >>> (arbitrary) size and analogously for [abstype] and [abst@ype]. >> >>This seems to be the case. Thank you! And now this leads to another >>question. If absviewtype is always the size of a pointer, and >>absviewt@ype can be of any arbitrary size, why is it possible to have >>an empty value for an absviewt@ype declaration? For example.. >> >>absviewtype foo1 (b:bool) = int // rejected >>absviewtype foo2 (n:int) = ptr // OK >>absviewtype foo1 (b:bool) // We know it is the size of a pointer >> >>absviewt@ype bar1 (b:bool) = int // OK, size of int >>absviewt@ype bar2 (n:int) = int // OK, size of a pointer >>absviewt@ype bar3 (b:bool) // OK, no size, proposition only? Declared as such, bar3 has *unknown* size. Therefore, if you do something like: let var x: bar3 in ... end The C compiler will complain as it cannot compute the size for [x]. Then what is the use of bar3? Well, you can have a function like foo: fun foo (x: &bar3): int which uses call-by-reference to pass a parameter of type [bar3]. >>I'm guessing it has no size (void)? Or maybe I have misunderstood? According to C, sizeof(void) = 1. In ATS, there is a type [empty] whose size is 0. --Hongwei Computer Science Department Boston University 111 Cummington Street Boston, MA 02215 Email: hw...@cs... Url: http://www.cs.bu.edu/~hwxi Tel: +1 617 358 2511 (office) Fax: +1 617 353 6457 (department) |