Vijay Saraswat <vi...@saraswat.org> wrote on 04/13/2017 10:36:48 AM:
>
> By studying useful idioms in untyped languages, one can gain a better
> understanding of the challenges faced in designing a good type system.
>
> Here is the classic union-find algorithm in Python. Turns out that using
> just a single field at each node works fairly well. Assume each node has
> a uniquely identifying index (an int). Initially the field is a set (of
> cohorts), and eventually it transitions to an int (the index of the node
> this one is merged into).
>
> For a strongly typed language this is the basic challenge of dealing
> with typestate. There may be some leverage to be gained by designing a
> system that admits only a bounded number of type transitions (in this
> case, 2).
>
> (This "overlay" notion goes back to the 50s and 60s, when memory was in
> short supply and reusing the same storage block in different ways at
> different points in the algorithm made sense. We don't have that
> motivation any more. For me, the motivation was simply clarity of the
> code. By using *one* variable, I ensure that I do not have to manage
> semantic invariants across multiple distinct variables, e.g. an
> `in_cohort` in field and a `cohorts` int set field.)
I think Swift would support this nicely via enums with associated values
(effectively type-safe tagged unions).
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Enumerations.html
--dave
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users