The most natural way I can think of to implement
sets in ATS is the following one:

abstype
myset(a:t@ype) = ptr

extern
fun
{a:t@ype}
element(): myset(a)
extern
fun
{a:t@ype}
add(x0: a, xs: myset(a)): myset(a)
extern
fun
{a:t@ype}
member(x0: a, xs: myset(a)): bool

And here is a list-based implementation:

local

assume
myset(a:t@ype) = list0(a)

in (* in-of-local *)

implement
{a}
element() = list0_nil()

implement
{a}
add(x0, xs) = list0_cons(x0, xs)

implement
{a}
member(x0, xs) =
list0_exists(xs, lam(x) => geq_val_val<a>(x0, x))

end // end of [local]



On Wednesday, October 18, 2017 at 7:37:31 PM UTC-4, Andrew Knapp wrote:
>
> As a concrete example, an ATS port of the short ML example from this 
> message would be very helpful, even if none of the functions are actually 
> implemented.
>
> https://mail.haskell.org/pipermail/haskell/2004-August/014463.html
>
> I'd also like to know which of the features of the ML module system 
> described in that message can be replicated in ATS, and more generally, 
> what kind of support there is for the kind of modularity described by 
> Robert Harper here.
>
> https://existentialtype.wordpress.com/2011/04/16/modules-matter-most/
>
> A potential use case would be, for example, being able write code that is 
> "functorized" over atomics and threads, with implementations like
>
> a) pthreads and c11 atomics modules for production use
> b) userspace threads and atomics modules, which can be subjected to 
> randomized or exhaustive interleaving to check for concurrency bugs
>
> On Wednesday, October 18, 2017 at 1:39:50 PM UTC-7, gmhwxi wrote:
>>
>>
>> The following article may shed some light on this issue:
>>
>>
>> http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/DivideConquer/main.html
>>
>> If you can tell me something a bit more concrete, I will probably be able 
>> to say more.
>>
>> On Wednesday, October 18, 2017 at 3:53:34 PM UTC-4, Andrew Knapp wrote:
>>>
>>>
>>> Hello,
>>>
>>> Chapter 3 of "A Tutorial on Programming Features in ATS" mentions that 
>>> file inclusion can be used to emulate SML or OCaml style functors in a 
>>> limited manner.
>>>
>>> Is there an example of this technique somewhere? I would use the 
>>> record-based functor method, as described in the make_ratmod_intmod 
>>> example, but that has a performance cost.
>>> It prevents inlining and leads to calls through function pointers, both 
>>> of which I would like to avoid.
>>>
>>> Thanks,
>>> Andrew
>>>
>>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/1f34f185-6b50-40d9-aecd-f1d266d2523e%40googlegroups.com.

Reply via email to