
Algebraic Data Types in JavaScript - amelius
http://w3future.com/weblog/stories/2008/06/16/adtinjs.xml
======
tel
I've written something like this, essentially just providing sum types, but
it'e currently embedded in some code at work. If anyone is familiar with
putting ES6 NPM libraries together and would like to help, I'd be happy to
open source it.

------
sjoerd_visscher
Thanks for reminding me that I really should write an updated version of that
library!

------
madflame991

      Color = Data(function() ({ Red: {}, Green: {}, Blue: {}, Yellow: {} }))
    

Is this JS or pseudocode? There are some extra parens in there and the pattern
repeats everywhere.

~~~
tikhonj
Those are the JavaScript 1.8 (FF-only) "expression closures" the author
mentions. JavaScript 1.8 introduces a succinct syntax for anonymous functions:

    
    
        function (a, b, c) a + b * c;
    

which is the same as

    
    
        function (a, b, c) { return a + b * c; }
    

Of course, this syntax breaks down if you want to return an object literal
from your anonymous function. Curly braces are too overloaded in JS! Adding
parentheses disambiguates between the new and the old function syntax.

