News for hackers. Stuff that matters.
Re:Type-safe GraphQL with OCaml by aaron-lebo on Thursday November 30, 2017 @02:29PM (#15818743)
I wish OCaml had the libraries and community of Go or Rust, I think it'd be the most useful all-around language out there.
Re:Type-safe GraphQL with OCaml by lilactown on Thursday November 30, 2017 @02:41PM (#15818846)
I'm hoping the movement around ReasonML[0] could lead to both the web community being able to reap the benefits of OCaml's fundamentals, while also giving people a point of introduction to the OCaml community through web dev.

It has been my experience that the ReasonML community is incredibly welcoming to new comers, and is moving at a break-neck pace to find the right target of being approachable for people who are familiar with JS, but also empowering users to use all of OCaml's power to create web apps that are more simple and correct than they would otherwise be.

[0]: https://reasonml.github.io/

Re:Type-safe GraphQL with OCaml by noncoml on Thursday November 30, 2017 @03:01PM (#15818976)
I really don't understand why they had to invent a brand new syntax.
Re:Type-safe GraphQL with OCaml by quicksnap on Thursday November 30, 2017 @03:08PM (#15819041)
The short answer is that Reason's syntax is simpler and more enjoyable to use. I simultaneously learned both OCaml and ReasonML syntaxes and find Reason to be much easier to work with.

Perhaps people in Reason core will chime in with a more detailed answer. Here's some official information: https://reasonml.github.io/guide/ocaml/

Re:Type-safe GraphQL with OCaml by bad_user on Thursday November 30, 2017 @04:57PM (#15819954)
OCaml's syntax on the other hand is stable, whereas it is my impression that ReasonML changes with the same frequency that JS libraries are changed.

And the differences are very superficial. What trips people is not the actual syntax, but the concepts learned, the rules of the type system, scoping rules, etc, which don't change.

I'm glad that ReasonML exists, but personally I would use OCaml instead of risking that my codebase gets stuck with an old release after only six months because the current version now has different opinions about how to express anonymous functions.

Re:Type-safe GraphQL with OCaml by lilactown on Thursday November 30, 2017 @05:09PM (#15820042)
You're right in that ReasonML syntax is a bit of a moving target, but I think it's part of the initial pains of their effort to provide an approachable port into the ML world. The syntax should stabilize eventually. The maintainers are aware of the churn they are creating, and have deemed it worth it.

That being said, I have a bunch of old projects written in Reason 2 (which still work; the tooling has preserved perfect backwards compatibility[0]), and recently started a new project using the new Reason 3 syntax. It was easy enough to pick up the new syntax in about a day. I haven't done it yet, but my understanding is that it's completely automated[1].

[0]: https://reasonml.github.io/community/blog/#reason-3

[1]: https://github.com/reasonml/upgradeSyntaxFrom2To3

Re:Type-safe GraphQL with OCaml by jordwalke on Friday December 01, 2017 @12:32AM (#15822142)
We provide tools to automate the upgrade between any two reason versions. It’s actually pretty trivial to keep up with changes due to refmt.
Re:Type-safe GraphQL with OCaml by noncoml on Thursday November 30, 2017 @03:30PM (#15819223)
Yeah, I guess the complaint comes from a guy that was already familiar with OCaml's syntax.

I guess if you don't know OCaml, maybe the Reason syntax is more appealing.

Re:Type-safe GraphQL with OCaml by jordwest on Thursday November 30, 2017 @03:59PM (#15819481)
I learnt Reason syntax first, then OCaml second. I prefer the OCaml syntax, it seems simpler, cleaner, and doesn’t hide the nice things about the language behind JavaScript semantics.

The biggest example I can think of is that OCaml uses let..in, which reminds you that every function is a statement. By contrast, the `;` in Reason hides that fact.

That said, it was the Reason syntax that first brought me to the ecosystem, and I think it’s going to be the catalyst that makes OCaml a big player in front end.

Re:Type-safe GraphQL with OCaml by jordwalke on Thursday November 30, 2017 @11:23PM (#15821878)
> “The biggest example I can think of is that OCaml uses let..in, which reminds you that every function is a statement. By contrast, the `;` in Reason hides that fact.”

... Except in OCaml modules/files where you don’t use “in”. OCaml still has “semicolons” for let bindings - but they are just spelled as “in” or “let () =“ depending on the the context. All but one of these “semicolon” forms have nothing to do with language semantics and are only used to help the parser figure out how to group bindings and values. It doesn’t make OCaml’s core semantics worse or better- though it might make it harder to learn initially or copy/paste code between different contexts.

The point of ; in Reason is merely for consistency - to have exactly one way to form bindings whether you are in a module or expression, allowing you to copy paste lines between the two contexts. Compare that to OCaml which requires different syntax depending on the context and copying values from module bodies to expressions requires a lot of editing. There may be other ways to achieve the same kind of consistency without semicolons and we are open to them - just so long as they are consistent across all contexts and easy to learn. (And as long as they don’t have major foot guns like JS’s ASI).

(Often people object to ; as a parsing separator because they think it means “side effect”. It doesn’t. Not in Reason. Not in OCaml. OCaml features ubiquitous use of semicolons for everything from arrays, lists, to records field separators, all things that have nothing to do with side effects. And if you still haven’t had your fill, there’s the ;; double semicolon - which actually does typically imply side effects).

Re:Type-safe GraphQL with OCaml by lilactown on Thursday November 30, 2017 @03:58PM (#15819466)
I do miss a lot of the parentheses-less-ness of OCaml (and the old Reason syntax), but I'm honestly a lot more comfortable at least broaching the topic of using it on some work projects now that it's more JavaScript-y.
Re:Type-safe GraphQL with OCaml by ch4s3 on Thursday November 30, 2017 @03:07PM (#15819029)
Probably because they were first trying to sell an ML internally and it sounded like OCaml/Bucklescript didn't catch on. I think the new syntax is the raison d'etre to some extent.
Re:Type-safe GraphQL with OCaml by k__ on Thursday November 30, 2017 @03:12PM (#15819082)
Yes, many devs know stuff with C/Java/JavaScript like syntax.
Re:Type-safe GraphQL with OCaml by ch4s3 on Thursday November 30, 2017 @03:34PM (#15819259)
Yeah, for better or worse that's ort of the default. I think ML syntax is fine, and in some cases great. However very few CS programs seem to teach MLs and AFAICT no bootcamps do so these languages tend to get picked up by dedicated autodidacts and academics. ReasonML might be a nice bridge,
Re:Type-safe GraphQL with OCaml by k__ on Thursday November 30, 2017 @04:13PM (#15819591)
I used LiveScript until ES2015 was a thing and found ML syntax rather nice.
Re:Type-safe GraphQL with OCaml by abiox on Thursday November 30, 2017 @03:13PM (#15819095)
to varying degree, syntax matters. (for better or worse.) the nice thing is that the semantics of ocaml haven't been changed by reasonml.
Re:Type-safe GraphQL with OCaml by ernst_klim on Friday December 01, 2017 @01:57AM (#15822421)
>I wish OCaml had the libraries and community

What's wrong with the libraries and community? There are thousands of libs in opam repository and although community may be smaller than Go's, the quality of OCaml community is incredibly high.

Re:Type-safe GraphQL with OCaml by hajile on Friday December 01, 2017 @01:25AM (#15822319)
I wish SML were more popular. The syntax is much better and regular. I'll be done teaching you advanced SML language features before I could finish teaching the basics of ocaml.

SML also has a multithreaded implementation in polyml and a better compiler in mlton. The standard library is not big enough, but at least there aren't 4 like in ocaml (std, core, batteries, and container).

The only issue is that just a little more syntax would be nice, but the next gen group is working on that.

Re:Type-safe GraphQL with OCaml by c-cube on Friday December 01, 2017 @05:57AM (#15823134)
Nowadays, OCaml has so many more syntactic sugar and typing goodies compared to SML, that it's not fair to compare them anymore. I'm no expert in SML, but from what I know:

- OCaml's pattern matching is more powerful (more or-patterns, lazy, matching records with field-puning): `match x with lazy {x; y; z=(None | Some 0); _} -> x+y`

- GADTs along with phantom types: many things are now type-safe (including the builtin format strings)

- inline records in sum types: `type 'a tree = Empty | Node of { left: 'a tree; mutable key: 'a; right: 'a tree; }`

also, I prefer `let x = y in …` rather than SML's equivalent which forces nesting because of the final `end`.

In addition, flambda generates very good code. I don't know if it's as good as MLTon, but it's definitely an improvement.

(edit: formatting)

Re:Type-safe GraphQL with OCaml by hajile on Sunday December 03, 2017 @07:27PM (#15840544)
Ocaml is a mess. Just like C++, PHP, or Perl, it's spent way too much time bolting extra stuff here and there until different codebases can look like completely different languages. Ocaml's features don't flow well together and make it very hard to teach the language (as used in the real world) to new developers.

Golang has fewer features than Ocaml and is worse in almost every way, but people love it's simplicity. The best language features are the ones you can add without significantly increasing syntactic complexity.

I agree that Ocaml has some great features that the current SML spec lacks. That spec is 20 years old now. There's plenty of room to look at Ocaml features and pick a good set that does enough of the things without blowing up the complexity.

SML's let expression is definitely superior to Ocaml's. Ocaml has two different `let` expressions -- one for top-level and one for sub-expressions.

To borrow from a comparison [here](http://adam.chlipala.net/mlcomp/)

    (* Ocaml *)
    let six = 6
    let rec fact x = if x = 0 then 1 else x * fact (x - 1)

    let six_fact =
      let six = 6 in
      let rec fact x = if x = 0 then 1 else x * fact (x - 1) in
      fact 6

    (* SML *)
    val six = 6
    fun fact x = if x = 0 then 1 else x * fact (x - 1)

    val six_fact =
      let
        val six = 6
        fun fact x = if x = 0 then 1 else x * fact (x - 1)
      in
        fact 6
      end
SML groups multiple declarations together which provides greater clarity IMO while having an end keyword helps identify the let block.
Re:Type-safe GraphQL with OCaml by ernst_klim on Monday December 04, 2017 @01:16AM (#15841837)
>Ocaml's features don't flow well together

May you provide an example of features which don't flow well together?

Re:Type-safe GraphQL with OCaml by apatil on Thursday November 30, 2017 @03:26PM (#15819202)
I wish OCaml could just use the libraries of Go and Rust. They can both compile to object files, and their type systems can be mostly modelled in OCaml's.
Re:Type-safe GraphQL with OCaml by tonyhb on Thursday November 30, 2017 @03:41PM (#15819317)
OCaml can call external libraries via FFi functionality. I've only done this with Bucklescript (which makes it easy, the JS doesn't need to be compiled) though RWO walks through binding a C library: https://realworldocaml.org/v1/en/html/foreign-function-inter.... Wonder if this could be used with the go/rust compiler?
Re:Type-safe GraphQL with OCaml by apatil on Thursday November 30, 2017 @03:50PM (#15819384)
It's definitely possible today, I just wish it were closer to seamless. For example, it seems like it would be possible to write a utility that takes a Go source file and emits a .cma, and maybe an .mli so you can see what's in there.
Re:Type-safe GraphQL with OCaml by kornish on Thursday November 30, 2017 @04:38PM (#15819786)
It'd be great to have a good multicore concurrency/parallelism story too. Looks like Multicore OCaml is slowly and steadily making progress.
Re:Type-safe GraphQL with OCaml by StreamBright on Thursday November 30, 2017 @03:40PM (#15819308)
What exactly are you talking about? OCaml has decent libraries for almost everything that you want to do. What exactly are you missing?
Re:Type-safe GraphQL with OCaml by kornish on Thursday November 30, 2017 @04:35PM (#15819758)
"decent" and "almost" are generous, and it's completely realistic to say that Go, Java, Python, and Ruby's ecosystems far outshine OCaml's.

Love it as a language, but the ecosystem and community have a ways to go before even slightly widespread adoption.

Re:Type-safe GraphQL with OCaml by Drup on Thursday November 30, 2017 @04:43PM (#15819833)
Do you have concrete examples of things you are missing?
Re:Type-safe GraphQL with OCaml by kornish on Thursday November 30, 2017 @06:08PM (#15820499)
My biggest gripes are, in order: lack of library documentation, discoverability, maturity, and existence. Disclaimer: this is all anecdotal and the last time I dove into OCaml for side projects was about a year ago.

1. Documentation. Anecdotally, when you find a library that's not by Jane Street or top-20 starred on GitHub, the odds are low of finding a useful README or example code. God bless the developer if there are tests, but that seems to be rare as well.

2. Discoverability. OCaml's ecosystem sees tons of code for useful but non-major tasks floating around in various GitHub repos, where installation is tricky. I want to use a part of speech tagger? Great, I found a library with no documentation on GitHub - now how do I get it into my application? Why isn't it in the OPAM repo? I found an elasticsearch client library with no documentation on GitHub? Great - now why isn't it in the OPAM repo.

3. Maturity. Of the myriad library code floating around on GitHub, very little of it is what I would consider production-ready, by merit of lack of testing, lack of community, lack of documentation, and lack of frequency of updates.

4. Existence. Frequently, libraries don't exist which do in other languages. In the past couple weeks, I've pulled in Go and Java libraries for crontab parsing and execution, a MySQL ORM, inflection of English words, and various NLP utilities like the Stanford parser.

All languages have these problems to some degree, but the fact of the matter is that while OCaml is a beautiful language for closed domains, I can't in good faith recommend it for building production systems to interact with the outside world. Other languages give you many of the benefits of the type system with much less of the hassle (looking at you, Kotlin). Writing production systems in OCaml can be done, absolutely - my hat is off to Yaron Minksy and the folks at Jane Street - but there are tradeoffs.

And we're not even getting into developer tooling; this is just libraries.

All counterarguments welcome; it'd be wonderful to hear that OCaml is gaining in developer productivity and production readiness over time. I have great faith that ReasonML can get lots of Javascript folks more interested, and the increased demand for libraries should hopefully lead to the filling of holes in the ecosystem. Most of OCaml's problems stem from it being simply unpopular.

Re:Type-safe GraphQL with OCaml by jordwalke on Friday December 01, 2017 @01:44AM (#15822387)
This is some solid feedback, thanks for taking the time to write it up. I work on ReasonML, so a lot of this feedback describes problems we’d like to help the OCaml community solve. We are making progress on the popularity front by leveraging the JS ecosystem and it is proving to be an effective approach due to the size and openness of the JS community. Meanwhile the OCaml ecosystem (libraries, compilers, build systems(see jbuilder and its docs)) have been improving in the last two years so I would recommend checking it out sometime soon again.

I had a different experience with OCaml libraries. I’ve found some great gems in the OCaml ecosystem. For example, Menhir is an excellent parser generator used in Reason itself and it’s well documented and very powerful. I think many of these great pieces of the ecosystem stay hidden due to the exposure problem you mentioned, which comes back to popularity.

Another major missing piece of the library story was a way to build web apps using the most common web frameworks so we developed Reason React as part of the ReasonML project. https://reasonml.github.io/reason-react/ It’s definitely not a “bolted on” approach to React - it’s carefully thought out and in my opinion the API improves significantly upon React in ways that can only be done with language level type system features. Reason React is how I wish React always was.

Apologies for hijacking the GraphQL library thread to plug our project.

Re:Type-safe GraphQL with OCaml by kornish on Friday December 01, 2017 @02:10AM (#15822458)
My pleasure, Jordan - thanks for the great work you and your team do on ReasonML.

I agree that OCaml has some brilliant libraries for problems which are, in other languages, difficult or unpleasant to solve (parsing being one of them). Menhir is wonderful. However, that doesn't preclude gripes 3 & 4 from above. If a language seeks to be general-purpose, the existence of some truly great libraries doesn't redeem a need for dependable solutions to a multitude of problems.

I think OCaml can have a place in an organization's software stack today - but it will not gain the spotlight until its library offerings have the variety, robustness, and accessibility of other ecosystems. Would I write an internal parsing service using Menhir and expose over Protobuf? Absolutely. Would I write a heavier-duty application server that had to parse something, then talk to Postgres? Perhaps not - and that's a shame.

Love Reason React. I'm a huge static typing proponent where possible, and combining the semantics of OCaml with React is a great move.

Writing the occasional typed FFI wrapper into a Javascript library isn't the worst thing in the world. Most of my complaints for libraries center around server side OCaml/ReasonML development, which is where I have the most experience. (and that experience is admittedly limited)

Re:Type-safe GraphQL with OCaml by ernst_klim on Friday December 01, 2017 @02:14AM (#15822470)
>crontab parsing and execution

10 minutes with angstrom and unixlib?

Sure, ocaml does not have javascript/go-style libs like leftpad, but it provide a great ability to solve generic tasks with more generic libraries like angstrom, menhir, faraday, lwt or react.

>I can't in good faith recommend it for building production systems to interact with the outside world

Why is that so? I believe in exactly opposite. We are building quite a big telecom infra with ocaml, and it shines. In really critical systems (something beyond silly guest pages) you can't rely on low quality third party libs (which are usually provided by go), you have to write things by yourself or use some very generic stuff, and that is where ocaml shines. Both the language and major libs in opam are of an outstanding quality, people behind mirage, ocaml, angstrom, react, lwt are so collaborative and smart, and libraries are so transparent and beautiful that it is easy to understand how things work and what's happening under the hood.

Re:Type-safe GraphQL with OCaml by kornish on Friday December 01, 2017 @03:31AM (#15822703)
Totally fair - no experience here in deploying OCaml for production. Agreed that the language and major libraries are phenomenal. My intuition is that the maintenance time cost of writing and extending these abstractions from scratch in the face of changing business requirements is higher than the time cost of using a less perfect language but richer ecosystem; but that could be totally wrong.

Glad the language is shining in your situation. Can you elaborate more on team composition, tenure, learning curve, and use case?

> 10 minutes with angstrom and unixlib?

https://github.com/robfig/cron is ~1.5KLOC - sure, it's Go, but that's a bit more than 10 minutes in any language, especially to change gears and think through edge cases. I'd prefer for things to Just Work.

> low quality third party libs (which are usually provided by go)

My experience with Go libs is that because the ecosystem is large and expanding fast, a surprising number of problem domains have one or two great standout libraries among a ton of noise. But it turns out one or two great libraries is frequently all you need. I dislike the language from a theoretical standpoint but after working full time in it for several years, can't deny that it's good for Getting Shit Done.

Re:Type-safe GraphQL with OCaml by ernst_klim on Friday December 01, 2017 @03:43AM (#15822732)
>requirements is higher than the time cost of using a less perfect language but richer ecosystem; but that could be totally wrong.

Believe me, breakdowns will cost much more, especially if your device has no ssh, connected via ASI/some military obscure one-directional interface. I found that in many fields it's incredibly hard to approve third party libs usage, even some basic stuff like boost.

>~1.5KLOC - sure, it's Go, but that's a bit more than 10 minutes

Well, it is Go.

This is go json parser:

https://github.com/buger/jsonparser/blob/master/parser.go

And this is angstrom:

https://github.com/inhabitedtype/angstrom/blob/master/exampl...

cron should be easier, it's either vars or cronlines, which are trivial. I prefer to write it in angstrom than to catch some unexpected panic in go because of type coercion or similar shit.

Re:Type-safe GraphQL with OCaml by StreamBright on Friday December 01, 2017 @08:13AM (#15823567)
And I consider this as a great thing. It is much better to have a few rock solid libraries than a massive amount of subpar ones.
Re:Type-safe GraphQL with OCaml by StreamBright on Friday December 01, 2017 @03:12AM (#15822643)
I am not sure about this. As an anecdotal evidence, I was definitely running into more issues with Go and Python than with OCaml.
Re:Type-safe GraphQL with OCaml by Nelkins on Friday December 01, 2017 @02:15PM (#15826431)
Take a look at F#. Huge library (all of .NET), cross-platform, has JS as a target, and is a great community.
Re:Type-safe GraphQL with OCaml by noncoml on Thursday November 30, 2017 @03:02PM (#15818987)
+1

It's an awesome language, but the lack of libraries make it pretty much useless for small teams.