Example code for traits/mixins/multiple inheritance

60 views
Skip to first unread message

Brandon Barker

unread,
Mar 9, 2018, 4:50:19 PM3/9/18
to ats-lang-users
There is a small part of a project I'd like to convert to ATS where linear types could be helpful in tracking cancellation of running tasks (and other things I'm probably forgetting just now, but are on the issue tracker). The part I'm interested in tackling here implements referentially transparent methods on reactive variables. I'm sure I can find a way to do this without traits (mixins) but want to maintain as direct a port as possible. I have a feeling the answer may involve templates.

The other part of the project would be cool too, but it kind of depends on xml literals being a thing (or later, XML interpolation): using scala.js to write web pages that depend on these reactive variables. It is quite a fun little framework.

Artyom Shalkhakov

unread,
Mar 28, 2018, 3:25:10 AM3/28/18
to ats-lang-users
Hi Brandon,


On Saturday, March 10, 2018 at 3:50:19 AM UTC+6, Brandon Barker wrote:
There is a small part of a project I'd like to convert to ATS where linear types could be helpful in tracking cancellation of running tasks (and other things I'm probably forgetting just now, but are on the issue tracker). The part I'm interested in tackling here implements referentially transparent methods on reactive variables. I'm sure I can find a way to do this without traits (mixins) but want to maintain as direct a port as possible. I have a feeling the answer may involve templates.

The other part of the project would be cool too, but it kind of depends on xml literals being a thing (or later, XML interpolation): using scala.js to write web pages that depend on these reactive variables. It is quite a fun little framework.

Seems like a lot of fun! How does it work? I was at some point thinking of faking HTML/XML literals in ATS using a preprocessor...

Brandon Barker

unread,
Mar 29, 2018, 1:51:55 PM3/29/18
to ats-lang-users
Hi Artyom,

I believe what is happening is that current Scala actually has literals defined as part of the language. It also relies on a library called scala-xml to actually model and work with the parsed xml literals; the monadic-html project uses a stripped down version of scala-xml that is included in the project. 

However, I've heard that nextgen Scala (dotty) will use XML interpolation like: 
val myXml = xml"<someXml></someXml>"

So maybe not quite as nice, but it saves complexity in the compiler in a "post-XML era"; I don't think this has been implemented in dotty as yet:

When I try I get the following error:
|value `xml` is not a member of StringContext - did you mean `StringContext.s`? 

This implies that it will indeed be done as a library, when can presumably be overridden by using Scala Implicit classes to perhaps supply your own StringContext, but it sounds like there are a few competing solutions that are yet to be fleshed out.
Reply all
Reply to author
Forward
0 new messages