Tuples/Records in the statics

49 views
Skip to first unread message

Shea Levy

unread,
Feb 23, 2015, 2:19:59 PM2/23/15
to ats-lan...@googlegroups.com
Hi all,

I know we have datasorts, but do we have something similar to build up tuples records of sorts? I know I can just use a single-constructor datasort, just wondering if there’s something more direct.

~Shea

Hongwei Xi

unread,
Feb 23, 2015, 2:45:32 PM2/23/15
to ats-lan...@googlegroups.com
There is no direct support for tuples in the statics.



~Shea

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/B75CEE5A-16BC-472F-B044-5AB8277921EB%40shealevy.com.

Shea Levy

unread,
Feb 23, 2015, 3:56:25 PM2/23/15
to ats-lan...@googlegroups.com
Is there any way to “unpack” datasorts, some kind of scase?

Hongwei Xi

unread,
Feb 23, 2015, 4:00:14 PM2/23/15
to ats-lan...@googlegroups.com
Could you write some pseudo code?


Shea Levy

unread,
Feb 24, 2015, 6:59:55 AM2/24/15
to ats-lan...@googlegroups.com
The ideal would be something like (for an ini parser I’m playing with):

sortdef loc_and_count = @{ loc = addr, count = int }
vtypedef sized_array (a:t@ype, lc:loc_and_count) = (@[a][lc.count]@[lc.loc]|@{ sz = int(lc.count), addr = ptr(lc.loc) })
vtypedef ini_entry (section_lc: loc_and_count, key_lc: loc_and_count, value_lc: loc_and_count) = @{ section=sized_array(section_lc), key=sized_array(key_lc), value=sized_array(value_lc) }

Without records in the statics, something like this would be nice:

datasort loc_and_count = loc_and_count of (addr, int)
vtypedef sized_array (a:t@ype, lc:loc_and_count) = case lc of (l, i) -> (@[a][i]@[l]|@{ sz = int(i), addr = ptr(l) })
vtypedef ini_entry (section_lc: loc_and_count, key_lc: loc_and_count, value_lc: loc_and_count) = @{ section=sized_array(section_lc), key=sized_array(key_lc), value=sized_array(value_lc) }

These are of course just conveniences, but as it stands I need to name every static variable repeatedly.

Thanks,
Shea

gmhwxi

unread,
Feb 25, 2015, 9:37:20 AM2/25/15
to ats-lan...@googlegroups.com

You can introduce some constants:

stacst: loc : loc_and_count -> addr
stacst: count : loc_and_count -> int

Then write lc.loc as loc(lc) and lc.count as count(lc).

What is a bit tricky is here is to tell the system of the following equalities
when you need them:

loc(loc_and_count(l, c)) = l
count(loc_and_count(l, c)) = c
Reply all
Reply to author
Forward
0 new messages