News for hackers. Stuff that matters.
Re:Try OCaml by sandGorgon on Friday September 07, 2018 @06:38AM (#17933217)
Could someone from the ocaml world comment on Typescript vs Ocaml ?

Is Typescript as close you get to Ocaml world... without writing a "ml" ?

Re:Try OCaml by rainygold on Friday September 07, 2018 @06:43AM (#17933246)
No. Reason would be the closest you can get without using OCaml itself.
Re:Try OCaml by masklinn on Friday September 07, 2018 @06:47AM (#17933261)
Reason's actual name is Reason ML, and is just a different syntax for regular OCaml.

Clean or Purescript or Haskell or Rust would be the closest you can get to the OCaml world without writing the word ML.

Re:Try OCaml by reycharles on Friday September 07, 2018 @07:45AM (#17933500)
No, Reason's actual name is Reason. The Reason ML name is similar to Go's "golang" name -- to work around the SEO nightmare the choice of the name really is. Your comment is otherwise correct in that Reason is an alternative syntax for good 'ole OCaml.
Re:Try OCaml by musha68k on Friday September 07, 2018 @07:59AM (#17933557)
IIRC it was simply called Reason at first but then the slightly more descriptive ML was added for better searchability. People call it both Reason and Reason ML now. That seems fine to me :) You are right it mostly is just a different syntax for OCaml but like in the Erlang/Elixir case there is a bit more to the story (js interop, js ecosystem, new ideas here and there, more diverse community as a result, etc).

I still call it reason, especially when I talk about it with other js developers ;)

Re:Try OCaml by stplsd on Friday September 07, 2018 @06:50AM (#17933280)
F# is as close you get to OCaml world without writing a "ml".

Typescript is unrelated to OCaml in any way.

Re:Try OCaml by remify on Friday September 07, 2018 @08:13AM (#17933629)
This, F# is the modern and more friendly (syntax, interoperability ...) version of OCaml.

I'd say the link between TypeScript and F# is the pragmatic approach that Microsoft took. Different paradigms but with the same care for usability. They are both great language for projects.

Re:Try OCaml by winter_blue on Friday September 07, 2018 @09:54AM (#17934219)
Besides ReasonML (a dialect of Ocaml), if you’re looking for a layer on top of JavaScript or a supersets of JS that has a type system similar to or inspired by Ocaml, Flow comes closest: https://flow.org

Flow has a quite powerful type system that mimicks (and is inspired by) OCaml. Flow itself is written in Ocaml, by Facebook.

Re:Try OCaml by galfarragem on Friday September 07, 2018 @06:45AM (#17933254)
Probably Typescript is as close you get to Java world using web technologies.
Re:Try OCaml by lingz on Friday September 07, 2018 @06:56AM (#17933299)
I disagree, Typescript has algebraic data types, conditional types, type inference, type guards, many or all of which are missing in Java. The class syntax is just another optional feature and it is possible to write quite functional / ocaml like code in typescript.
Re:Try OCaml by k__ on Friday September 07, 2018 @06:59AM (#17933312)
It's more like C# than Java.

But on the other hand, C# is more like Java (with extras) than JavaScript, haha.

Re:Try OCaml by k__ on Friday September 07, 2018 @06:57AM (#17933301)
Does TS has pattern matching?
Re:Try OCaml by mirekrusin on Friday September 07, 2018 @07:38AM (#17933466)
No and that’s one of biggest problems, pattern match is runtime decision not compile time one. It’s a shame because pattern matching with algebraic types is the full picture of the whole thing. Without it it’s just one-legged weirdo. It would be possible to emit runtime checks, similar to how tcomb+flow does it, but that’s not gonna happen anytime soon.
Re:Try OCaml by pseudonom- on Friday September 07, 2018 @11:45AM (#17935184)
You can use switch statements for a pattern matching analogue. See the "Exhaustiveness Checking" heading at https://www.typescriptlang.org/docs/handbook/advanced-types.....
Re:Try OCaml by aikah on Friday September 07, 2018 @08:06AM (#17933590)
The goal of typescript is to provide static type analysis at compile time and mimic Ecmascript spec features. If Typescript starts bundling a runtime with it to do things completely unrelated to Javascript, then it's not just javascript with types anymore, it becomes its own language which defeats the entire purpose of Typescript.

This trade off is good because there is no runtime overhead, only desugaring. Typescript should never become ML or anything else that Javascript is not. If you want pattern matching in Typescript you need to convince the Ecma committee to put pattern matching into Javascript first.

Re:Try OCaml by gmfawcett on Friday September 07, 2018 @08:45AM (#17933800)
Your comment seems like a non-sequitur. What does pattern matching have to do with runtimes?
Re:Try OCaml by k__ on Friday September 07, 2018 @09:52AM (#17934202)
Isn't one part of pattern matching to ask for a type and the other to ask which values the (instance?) of that type holds?
Re:Try OCaml by gmfawcett on Friday September 07, 2018 @12:08PM (#17935400)
When a language has algebraic data types -- i.e., data types that have multiple, disjoint constructors -- pattern matching generally means determining which constructor was used to create the value being matched, and branching on that. I'm guessing this is the kind of pattern-match that TypeScript users would be eager to have.

What I don't see is how this requires the addition of a "runtime" on top of the JS model to make it work. I don't use TypeScript, and don't know how it implements its data types, so there may be something obvious here that I'm missing.

Re:Try OCaml by wtetzner on Friday September 07, 2018 @09:35AM (#17934075)
Pattern matching doesn't require any kind of runtime support, and can be implemented through desugaring.
Re:Try OCaml by k__ on Friday September 07, 2018 @09:53AM (#17934212)
How so?
Re:Try OCaml by wtetzner on Thursday September 13, 2018 @06:28AM (#17977468)
Why would it need runtime support? It would just desugar into an if-else chain.
Re:Try OCaml by jaaames on Friday September 07, 2018 @10:55AM (#17934705)
I believe there was/is a stage 0 proposal for pattern matching in ECMAScript
Re:Try OCaml by k__ on Friday September 07, 2018 @11:06AM (#17934804)
Stage 1 and yes, this one simply uses destructuring.

But it could use JavaScripts own types.

But it couldn't use TypeScripts types.