How is scala.util.parsing.ast.Binders supposed to be used? - scala

I am currently implementing a small compiler in Scala and while I was doing the component for context analysis I discovered the trait Binders in package scala.util.parsing.ast (I am using Scala 2.9 RC), which is Documented to enable name binding during parse time. That sounds very interesting and I have been googling around a lot, but I still have no clue how to use it. While I am of course able to let my abstract syntax derrive from Binders I dont see how to proceed from there. Are there any examples of the usage on the net?

By googling a bit I found this page, which seems to be a development version of a documentation with more details. Unfortunately I was not able to find online (I mean, outside a source repository) version of these documentations.
I'm not sure however that you will find what you're looking for in this library. Name resolution is a rather delicate thing, and it smells like a questionable idea to do it during parsing. The documentation of this library itself highlights that it is only suitable for languages where the name resolution is relatively simple, and may not scale otherwise. Besides, none of the parsing examples in the Scala repository make use of this class.
I would cautiously avoid this uncharted territory, and design binding analysis in a separate post-parsing pass.

You're not supposed to use it. In fact, it has recently been deprecated.
See
deprecation candidate: scala.parsing.ast

Related

ReasonML vs Scala.js

So by reading the reasons why facebook choose OCaml to create Reason, I couldn't stop noting that Scala met all the requirements too.
I'm not biased whatsoever, I know Scala, but I'm not a die hard scala advocate. I just like a nice type system, so in this point I'm finding really hard to choose between those two for my next project. So what are the real trade offs here?
Reason react can do per file compilation so it’s easy to slip into an existing project. Scala.js allows you to tap into scala libs and the scala ecosystem. If you only focus on web it’s probably best to stick with what Facebook offers. I have computations that i do and for that Scala and non-ocaml tools are more helpful. Since you already know scala, you can use the reason-react model by using a library I put together at https://github.com/aappddeevv/scalajs-react.

ScalaJS: What's the state of the art for cross-platform dates?

I'm using ScalaJS with Play. Many of the models I'd like to use on both JS and JVM platforms involve dates and times. Given the lack of a cross-platform date/time library, how are people approaching this?
Things I know about:
scalajs-java-time project (https://github.com/scala-js/scala-js-java-time) to port JDK8's java.time api to Scala.js. Unfortunately, it's far from complete and judging by the commit logs, seems to have stalled.
https://github.com/mdedetrich/soda-time is a port of JodaTime to Scala/Scala.js. But it's not ready for production use.
An old post at https://groups.google.com/forum/#!topic/scala-js/6JoJ7x-VxLA suggests storing milliseconds in shared code and then doing implicit conversions on each platform to either js.Date or JodaTime. But we really need a common interface, which this doesn't give.
Li Haoyi's excellent "Hands-on Scala.js" has a simple cross-platform library (http://www.lihaoyi.com/hands-on-scala-js/#ASimpleCross-BuiltLibrary) that could, in theory, be extended to come up with an API in /shared that delegates to JodaTime on the jvm and Momento on js -- but that sounds like a lot of work.
(added later) https://github.com/soc/scala-java-time is based on an implementation of java-time that was contributed to OpenJDK. The README claims that most stuff is working. Right now, this looks like the most promising approach for my needs.
Any advice from those who have gone before me? Right now the fourth options seems like my best bet (with the API limited to stuff I actually use). I'm hoping for something better.
I was in the same boat as you, and the best solution I came up with was cquiroz's scala-java-time library. From reading the comments to your question above, it appears you landed at the same place eventually!
I came here from a google search, and given how much better this solution is than the alternatives you mentions above, let's consider marking this question as resolved for future visitors.

How to understand and use scala macro, and write a more complex function

The documentation of scala macro is very hard to understand, so I think it must have some background knowledge if one wants to use it in real case.
And I ask help for what these knowledge are.
c.Expr[Unit](Block(treesWithSeparators.toList, Literal(Constant(()))))
it is a code snippet of macro, and there are little info available for what Block means, and other similar terms. It is hard to go deep in if these key points lost.
So if anyone knows where exists a more detailed documentation or tutorial, please tell me, thanks:)
It is hard to go deep in if these key points lost.
Yes that is true but it is good that not everyone can get a way into macros. They are a powerful feature and users that don't understand them fully should not use them.
Diving into macros requires a lot of self learning, there is no easy way to learn how they work and how to work with them.
Nevertheless there is already a lot of useful documentation out there. For example this question wants to know how to understand the AST: Where can I learn about constructing AST's for Scala macros?
This question on the other side gives some value on how to work with reify: What's the easiest way to use reify (get an AST of) an expression in Scala?
On docs.scala-lang.org there is an excellent overview available that describes what macros can do and what not. The official homepage also contains lots of useful information.
And reading further questions here on StackOverflow, looking at source code on GitHub or searching the web for blog posts on macros shouldn't be that difficult.
For the beginning this should be enough to find a way into macro hell.

Is there a central site/page for "advanced Scala" topics?

Despite having read "Programming in Scala" several times, I still often finds important Scala constructs that were not explained in the book, like
#uncheckedVariance
#specialized
and other strange constructs like
new { ... } // No class name!
and so on.
I find this rather frustrating, considering that the book was written by the Scala "inventor" himself, and others.
I tried to read the language specification, but it's made for academics, rather than practicing programmers. It made my head spin.
Is there a website for "Everything "Programming in Scala" Didn't Tell You" ?
There was the daily-scala Blog, but it died over a year ago.
Currently, we're working on a central documentation site for scala-lang.org. We're hoping that this solves a lot of the documentation issues that new users face. More details on this effort can be found at http://heather.miller.am/blog/2011/07/improving-scala-documentation/, but in summary...
Believe it or not, there are a lot of documents that the Scala team has produced but which simply aren't in HTML or are otherwise difficult to find. Such as Martin's new Collections API, his document on Arrays, or Adriaan's on Type Constructor Inference.
One goal of such a site is to collect all of this documentation in one place, in a searchable, organized, and easy-to-navigate format.
Another goal is to collect excellent community documentation out there, and to put it in the same place as well. For that, we are actively looking for quality (article/overview-like) material with maintainers. Examples include the Scala Style Guide, and Daniel Spiewak's Scala for Java Refugees.
Yet another goal is to make it easy for contributors to participate- so the site is built from RST source, which will live in a documentation-only github repo at https://github.com/scala/scala-docs.
So, in short, something better is on it's way, and contributors are very welcome to participate.
EDIT: http://docs.scala-lang.org is now live.
Several documents considered to be rather detailed or even obscure are already available. This includes all "Scala Improvement Proposals" (the proposals produced when new language features are suggested, and which are usually very detailed, and written by the implementers themselves). Also available is the entire glossary from Programming in Scala, Scala cheatsheets, amongst many other documents. The bottom-line of the site is to be community-focused and contribution-friendly-- so, free, and totally open. Suggested topics to cover are also welcome.
Take a look at scalaz and typelevel librairies (shapeless, spire, etc.), they rely on many advanced features of Scala.
*scalaz was for a time part of typelevel, but it is no more the case.
Josh Sureth's book goes a little beyond the usual. It's not as far as I'd like but I'm not his core audience - still, there's a lot of good stuff in there.
http://www.manning.com/suereth
Scala IRC: irc://irc.freenode.net/scala
Scala forum: http://scala-forum.org/
Blogs: Just look at http://planetscala.com/
Programming Scala (Wampler, Payne): http://ofps.oreilly.com/titles/9780596155957/
Programming in Scala (Odersky, Venners, Spoon) - good but Scala 2.8: http://www.artima.com/pins1ed/
The new documentation page is online:
http://docs.scala-lang.org/
I've kept a library of advanced Scala resources, primarily talks and blog posts. It's updated pretty regularly as I find new, interesting content.
Happy to add new links to it if anyone has recommendations.
Try to read SBT Source: https://github.com/harrah/xsbt/wiki
Its a good exercise. Also check out the book 'scala in depth' : http://www.manning.com/suereth/ by
Joshua D. Suereth
I believe there are a lot of good answer here. But as a sharing of experience. I have been coding Scala for 2 year (not my full time job), and been progressively better at it. My project is 97% Scala, and I have been able to do most of it with:
Programming Scala
The scala-user list
Stackoverflow
This cover most of the need for the "user" side of Scala, meaning all you need to create working application. However if you want to write some more complex code, or create powerful typed libraries you definitely need more.
If you want to go beyond the basics and are prepared to delve deeply into type system, and libraries, then the alternatives I use:
Use the community, scala enthusiast are really nice. I have worked with folks form Specs, Scalaz and Lift.
IRC is really good and some of the core contributors to some of the big library frequently show up.
Jump to source code, but don't try to understand everything. Scala type system can be daunting, however you normally don't need to understand 100% of it to use it.
If you really need to get into the nitty gritty details, hit the language specs, development list, and get to know the key people.
However you can really be very effective in Scala without needing to understand every single bit of the language.

Implementing a security typed variant of Scala - which method is best?

Hio there Scala folks, I'm actually writing my master thesis and I have to implement a security typed language in Scala. So this means I have to add annotations to specify the special permissions levels for the variables and other programming constructs in Scala. The idea to add this comes from Jif (a real security typed language http://www.cs.cornell.edu/jif/) and FlowCaml (http://www.normalesup.org/~simonet/soft/flowcaml/). I still have to check how this languages add their security extensions.
I talked to my advisor and he suggested three possibilities how I can implement this feature in Scala:
source-to-source compiler (I don't think this is the best solution to write the things from the scratch because I will be busy with the parser and semantic and out of own experience I know that I don't have quite enough time to work on the main stuff)
type-checker plugin (I haven't wrote a plugin for compiler and think this just won't work on further versions of Scala because the compiler is still under development)
build a library in Scala (syntax are here simply free, so I can easily build something like this in a language I want => think this is like inventing a DSL and I believe that this is the best solution)
If you have another idea how to implement please let me know and if you have pros and cons for the methods mentioned above please let me know. I'm convinced that I will learn after this project of to program with pleasure in Scala (I'm familiar with Java and Ruby).
Greetings
Matthias Guenther
This is definitely a job for a compiler plugin: writing a plugin which allows annotations to further refine the possible subtype relationships is fairly straightforward, at least in simple cases.
You can be reasonably confident that the compiler plugin API will remain stable for the lifetime of a masters thesis, and you should investigate scala.tools.nsc.symtab.AnnotationCheckers and google for example plugins which implement compile time checks for (non-)nullability (ie. T #NonNull <: T, but not T <: T#NonNull) which is structurally similar to the simplest non-trivial security typed scheme.
Wow, this is quite a sizable project!
I think the answer to your question depends on if you're looking for a sound language addition or if you just want something that may be circumvented by the programmer but still might be helpful. Since you mention Jif and FlowCaml I assume you want to go the sound way and provide guarantees for your language. Then I don't think there is much option but create your own language constructs on top of Scala and provide a new frontend for those.
I very much doubt that you can implement security as a library in the style of Peng Li and Steve Zdancewic or Alejandro Russo. The reason is that Scala can have side-effects everywhere and that pretty much ruins any security guarantees that you can try to enforce.
Good luck!