News for hackers. Stuff that matters.
Re:Facebook Launches Flow, Static Type Checker for JavaScript by ufo on Tuesday November 18, 2014 @02:15PM (#8625710)
You can't really use sum types as they are found in Haskell in Javascript. With Haskell option types you do a pattern matching and create a new binding for the non-null value but in Javascript you don't do that - you keep using the same object that you tested against null.

    case mx of Just x -> f(x)
vs

    if (x != null){ f(x) }
What you can do in a Javascript-like language is use union and intersection types. However, they can get a bit complicated (specially if you allow unions of non-primitive types) and the extra flexibility can confuse the type inference a bit so I can understand them restricting things to the common case of handling null.
Re:Facebook Launches Flow, Static Type Checker for JavaScript by sonyandy on Tuesday November 18, 2014 @05:20PM (#8626756)
What about

  function nothing() {
    return {
      match: function(cases) { return cases.nothing(); }
    };
  }

  function just(x) {
    return {
      match: function(cases) { return cases.just(x); }
    };
  }

  just(1).match({
    just: function(x) { return x + 1; }
    nothing: function() { return 0; }
  });
Re:Facebook Launches Flow, Static Type Checker for JavaScript by jahewson on Tuesday November 18, 2014 @05:55PM (#8626943)
Right, but now you're not using null. The question was how to justify the use of sum types for null... not whether or not they could be emulated in some non-idiomatic manner.