Thursday, November 10, 2016

Case classes in Javascript

How can you have the "case" classes like And(1,2), which contains two variables in javascript. And(val a, val b) is a Scala synthax. Case classes serve for tagging your data, particularly needed in pattern matching. So far, I used Erlang's ["&", 1, 2] style (google for "tagged tuples" and "Erlang pattern matching") in javascript. But, It looks unreliable since anybody can construct such an array by mistake so that I won't be able to distinguish it from my wrapper class .

IRC advises typescript for typechecking. There is however probably no reason to afraid since we parse results of our parser and, if it tags everything properly, we would not have data in the tag positions. 

No comments: