design question

81 views
Skip to first unread message

Raoul Duke

unread,
Feb 8, 2022, 6:47:38 PM2/8/22
to ats-lang-users
hi, a scenario 

enum of n values. 
api function that takes the enum. 
but throws error for some subset of enum values. 

how could we statically be told, enforce do not call the api fn in those cases?

besides "rtfm". 

Vanessa McHale

unread,
Feb 8, 2022, 6:51:28 PM2/8/22
to ats-lan...@googlegroups.com
You could I suppose have a polymorphic type and pass in ‘void’. I had an idea for something here: http://blog.vmchale.com/article/ann

In ATS I guess it would be

datatype Impossible

datatype A(phantom: type) = A | B | C of (phantom)

Then A(Impossible) would be sort of like a subtype of A(void) or at least you could manipulate it like that.

I’m not sure such a solution is worth it though! Might be better to just RTFM :P

Cheers,
Vanessa McHale

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb7erubNjQotU8ap_J4_4Eaks%2B%3DDabqyZU6jeRnGMYGf7w%40mail.gmail.com.

Hongwei Xi

unread,
Feb 8, 2022, 8:34:04 PM2/8/22
to ats-lan...@googlegroups.com
Currently, my practice is just declare something like:

abstype myenum = int

or

abstype myenum(i:int) = int

Then implement 'myenum' somewhere in a file. It can clearly be done, but it is really tedious,
involving a lot of boilerplate type of code. I suppose some kind of meta-programming can be
supported so as to reduce/eliminate this kind of coding.


--
Reply all
Reply to author
Forward
0 new messages