>>On Tue, 27 Sep 2011, Roman Salmin wrote: >> >>>>Hi, >>>> >>>>I have following in sats file: >>>> >>>>datatype hist_dt (int, addr) = >>>> | {sz:nat} {l:addr} hist_dt (sz, l) of >>>> @{ >>>> size = int(sz), >>>> bin_w = double, >>>> bin_c = double, >>>> data = ptr l >>>> } >>>> >>>>viewtypedef histogram (sz:int, l:addr) = (free_gc_v (double, sz, l), >>>>array_v(double, sz, l) | hist_dt (sz, l)) >>>> >>>>fun make_histogram {sz:nat} ( sz: int(sz), w: double, c: >>>>double):[l:addr] histogram (sz, l) Since we are at it, I would like to offer a bit advice on using dependent types and linear types, though it is completely uncalled for :) First and foremost, please try to avoid complex types. For instance, in the above case, one should probably introduce a (boxed) abstract viewtype: absviewtype histogram_addr_int (l:addr, sz:int) stadef histogram = histogram_addr_int Then some member functions: fun histgram_get_bin_w {l:agz} {sz:int} (x: !histogram (l, sz)): double ... If histgram is heap-allocated, then you can have fun histogram_free {l:addr} {sz:int} (x: histgram (l, sz)): void Or you can have a version based on reference count: fun histogram_ref {l:addr} {sz:int} (x: !histgram (l, sz)): histgram (l, sz) fun histogram_unref {l:addr} {sz:int} (x: histgram (l, sz)): void Later, you can implement 'histogram_addr_int' as is done above (or in C directly). A good example is the ATS/Cairo API in $ATSHOME/contrib/cairo/. I have met a lot people genuinely interested in ATS. Unfortunately, they almost always gave up shortly after trying ATS a bit because they quickly buried themselves in complex types which I myself would have difficulty handling. Here is my sincere advice: 1. Use abstract types 2. Use abstract types more 3. If you are bravely fighting the type system, it is likely that you need even more abstract types. Just think of it like this: if you have to get down to the level of atoms and molecules whenever you try to build something, there isn't really much you can build *practically*. Cheers, --Hongwei Computer Science Department Boston University 111 Cummington Street Boston, MA 02215 Email: hwxi@... Url: http://www.cs.bu.edu/~hwxi Tel: +1 617 358 2511 (office) Fax: +1 617 353 6457 (department)