Enumerations

92 views
Skip to first unread message

Shea Levy

unread,
Nov 15, 2014, 6:16:58 PM11/15/14
to ats-lan...@googlegroups.com
Hello,

Is it possible to declare an enumeration of a given size, whose enumerators are not necessarily sequential from 0 to the top? For example, can I declare an enumeration Foo the size of an int, whose only valid values are Bar, Baz, and Qux, where Bar is represented by 1, Baz by 30, and Qux by 16?

Thanks,
Shea

gmhwxi

unread,
Nov 15, 2014, 6:43:13 PM11/15/14
to ats-lan...@googlegroups.com
How about the following approach:

abst@ype Foo = int
macdef Bar = $extval (Foo, "1")
macdef Baz = $extval (Foo, "30")
macdef Quz = $extval (Foo, "16")

Shea Levy

unread,
Nov 15, 2014, 6:50:03 PM11/15/14
to ats-lan...@googlegroups.com
Ah, yes that will do. Followup question: is it possible to use Foo in existentials/constraints? Can I for example write a function that takes any Foo except Baz?

-- 
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/10dcc58a-76cd-45a4-add9-706218ee6895%40googlegroups.com.

gmhwxi

unread,
Nov 15, 2014, 6:59:14 PM11/15/14
to ats-lan...@googlegroups.com
How about:

#define Bar 1
#define Baz 30
#define Quz 16

abst@ype Foo(i:int) = int

macdef Bar = $extval (Foo(Bar), "1")

fun
foo{i:int | i != Bar} (x: Foo(i)): void = ...

Shea Levy

unread,
Nov 15, 2014, 7:01:10 PM11/15/14
to ats-lan...@googlegroups.com
Ah, and how does the preprocessor know not to substitute in Bar in the LHS of the macdef?

gmhwxi

unread,
Nov 15, 2014, 7:04:25 PM11/15/14
to ats-lan...@googlegroups.com
Actually, I was not sure myself. I had to try it :)

The following style is probably better:

stadef Bar = 1 // Bar is static


abst@ype Foo(i:int) = int

macdef Bar = $extval (Foo(Bar), "1") // Bar is dynamic


fun
foo{i:int | i != Bar} (x: Foo(i)): void = ...

Shea Levy

unread,
Nov 15, 2014, 7:08:45 PM11/15/14
to ats-lan...@googlegroups.com
Ah, I should probably read up on stadef :) Thank you!

Reply all
Reply to author
Forward
0 new messages