Have you seen Elm? It's a very neat language, I think derived from Haskell, designed to be accessible for people who aren't into functional programming (which is me) but still has ADTs, and compiles into JS. I've not used it for anything yet but its design has heavily influenced a pure JS project I'm working on and made it a ton more manageable.
Compiling with VS2015
Collapse
X
-
Code:typedef union { ui_event_type type; struct mouseclick mouse; struct keypress key; } ui_event;
Not sure if D can do ADTs, but you can probably hack something similar using macros.
Code:void main() { import std.variant : Algebraic, visit; alias Option = Algebraic!(int, string); void print(const ref Option o) { import std.stdio : writeln; o.visit!((string s) => writeln("got string: ", s), (int n) => writeln("got number: ", n)); } Option o = 99; print(o); o = "some text"; print(o); o = 1024; print(o); }
Comment
-
No, not event close. You can pretend all you like, though .
One of the major points of ADTs is to make illegal states undrepresentable -- and unions don't do that. In fact they possibly even make things worse because the programmer may easily get it wrong... leading to UB.
These things still don't strike me as a super cool feature, though
(Interesting to see that D has an emulation of ADTs. I haven't tried D enough to know whether they're useful there, but having to use visitors to deconstruct (rather than true pattern matching) seems like it would basically cripple them.)
I promise you, if you actually start using "true" ADTs + pattern matching, you'll change your mind .
Anyway, we've veered quite a bit off topic from VS2015, so I'll stop here .Comment
-
Have you seen Elm? It's a very neat language, I think derived from Haskell, designed to be accessible for people who aren't into functional programming (which is me) but still has ADTs, and compiles into JS. I've not used it for anything yet but its design has heavily influenced a pure JS project I'm working on and made it a ton more manageable.Comment
-
And, yeah, the C++ template language, which kind of scarred me for life
Anyway, we've veered quite a bit off topic from VS2015, so I'll stop here .Comment
Comment