Bucklescript

let does not work in ES5 mode, which is still many browsers. If you notice in Bucklescript every variable gets a unique name, so if you do:

let b = 543
let b = b + 24
let b = b + 24
let b =
  let b x = x + b in
  let b x = x + (b x) in
  b 42

Will generate:

var b = 567;

var b$1 = b + 24 | 0;

var b$2 = 42 + (42 + b$1 | 0) | 0;

(Hard to craft code it does not optimize out ^.^) So there are no issues with var bindings, those issues only come up when using the same name in embedded scopes, which the compiler will not do, everything gets a unique name in any given scope or sub-scope. And nope, never had an issue. :slight_smile:

It would fit very well on the BEAM too, the segmented process style of the BEAM would fix OCaml’s multi-thread woe’s. :slight_smile:

3 Likes

Well, there’s alpaca out there. I’m pretty sure you could be a great contributor to the project.

2 Likes

I’ve already been in their issues and reports, I’ve given suggestions on syntax and such. ^.^

It is still not OCaml though and missing a lot of functionality that OCaml has. And one big thing I’d want is to have the same language from the front-end and the back-end for ease of use and brain-switching.

1 Like

8 posts were merged into an existing topic: Elm - General Discussion, Blog Posts, Wiki

For note, I made a post (well actually I made it a few days ago) on making a new Bucklescript project that also shows how to use NPM as a build system: https://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt1-setup/

4 Likes

Part 2 is up now as well: https://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt2-overall-design-and-the-views/

I also put the output of each part at the bottom of each page so you can click it to see the final product of that step.

6 Likes

And part 3: http://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt3-game-types/

4 Likes

Part 4 up: http://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt4-actions/

It actually does things now instead of just looking like… something. ^.^

See the example link at the bottom as in every post. :slight_smile:

1 Like

Part 5 post is up: https://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt5-transformation-of-resources/

The output app actually does stuff other than just display now!

Part 6 post is up: https://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt6-serialization/

No ‘visual’ change from last time, except reloading the page does not reset it as it now supports saving and loading (with an auto-save every 10 seconds).

3 Likes

I recently did some ELM on frontend for simple work-related tool, and I really liked it. Also having a good IDE plugin like the one for Jetbrains IDEA was very helpful (I do Elixir in IDEA too).

Now the real question. Is there any IDE, or at least editor (with autocomplete, go-to definition, and linting) for BucklsScript (beside Vim, or Emacs ones, although I tried, I don’t like them that much )?

I tried VS Code with Ocaml plugin, but it shows way to many errors in my code that compiles perfectly. I wan’t to try bucklescript with OAK-TEA and follow @OvermindDL1’s tutorial, but I’m so used to good in editor hinting, that I have very hard time without those proper hints. :cry:

I believe the support in VSCode is currently one of the best for OCaml (and therefore, BuckleScript). I think most editor hint errors is caused by incorrect Merlin configuration… I’ve encountered them a few times too. What kind of errors are you seeing?

Huh :scream: I opened project with VS Code and no I see no errors!

Maybe it didn’t read configuration properly or… I don’t know. I’ll get back to it, and post more if I encounter any errors.

2 Likes

Any that works for OCaml works.

So there is emacs, vim, Atom, VSCode, IntelliJ, and at least a dozen others. OCaml already has a ‘build server’ kind of thing for a long time now called merlin and they all use merlin so they all have similar abilities, but it is awesome. In Atom I get red wavy underlines on errors, type information on hover, etc… etc… :slight_smile:

If you are having it work on bucklescript then make sure you have merlin (I’ve no doubt it uses merlin, thus you need ocaml-merlin installed) and make sure that you did not disable the .merlin file generation by the bucklescript build system (it builds it by default to set up merlin to understand the javascript’ness of it).

Actually, as much as I would like to see emacs, the best out is easily Atom. Facebook uses OCaml heavily and their Nuclide or Reactor whatever plugin system it was called is fully setup for OCaml (I recommend installing the ocaml plugins separately instead of that though, but a lot are made by facebook) and it is intensely powerful.

You still need ocaml-merlin installed though. :wink:

Maybe you did not build the project at least once? That would create the .merlin file then.

Ok, errors were shown as soon as I started to type :wink:

I followed directly @OvermindDL1’s tutorial http://blog.overminddl1.com/posts/bucklescript-tea-game-overbots-pt1-setup/

For the file

open Tea
open Overbots_types


let init () =
  let model = {
    msgs = [];
    resource_values = Overbots_resource.init_resource_values;
    bool_flags = init_bool_flags;
    int_flags = init_int_flags;
  } in
  (model, Cmd.none)

let update model = function
  | NothingYet -> (model, Cmd.none)

let subscriptions _model =
  Sub.none

type model = {
  msgs : game_msg list;
  resource_values : resource_value ResourceMap.t;
  bool_flags : bool_flags;
  int_flags : int_flags;
}

let main =
  App.standardProgram {
    init;
    update;
    view = Overbots_view.view;
    subscriptions;
  }

I get those errors

with this .merlin content

####{BSB GENERATED: NO EDIT
FLG -ppx /Users/bartosz/Documents/OCaml/overbots/node_modules/bs-platform/bin/bsppx.exe
S /Users/bartosz/Documents/OCaml/overbots/node_modules/bs-platform/lib/ocaml
B /Users/bartosz/Documents/OCaml/overbots/node_modules/bs-platform/lib/ocaml
FLG -nostdlib -no-alias-deps -color always -w -40+6+7+27+32..39+44+45
S /Users/bartosz/Documents/OCaml/overbots/node_modules/bucklescript-tea/lib/ocaml
B /Users/bartosz/Documents/OCaml/overbots/node_modules/bucklescript-tea/lib/ocaml
S src
B lib/bs/src
####BSB GENERATED: NO EDIT}

Although it all compiles nicely!

And even if I make a typo, or forget to write something, compiler nicely prints relevant easy to fix error.

PS. Strangely enough, after simply cloning overbots repo doing npm install and then npm run build I get first in this file node_modules/bucklescript-tea/src/tea_json.ml errors

Error: Unbound value reify_type
Hint: Did you mean reifyType?
ninja: build stopped: subcommand failed.

But after fixing them there I get anther error

File "overbots/src/overbots.ml", line 19, characters 23-46:
Error: Unbound module Ex
ninja: build stopped: subcommand failed.

And I think that what Bucklescript is lacking most is good tutorials showing how to write simple apps. A Phoenix + Bucklescript ( + maybe React/Vue/whatever) simple Todo crud app with ie. some websockets usage would be something that could really help with adoption of Bucklescript.

PPS. For me Phoenix and Elm, a real use case (pt. 1) · bigardone.dev was enough to boost my ELM knowledge to a level where I can write a mildly complicated app that has real world usage (internal in company but still)

And another big thanks from my side to @bigardone for that tutorial :wink:

Yeah ignore that, Bucklescript had backwards-incompatible changes recently, bucklescript-tea itself is updated, but not my example there. ^.^;

If you force updated bucklescript-tea to the latest version in that example project then it ‘should’ work though, I kept the interface the same to hide Bucklescript’s updating. :slight_smile:

@OvermindDL1 Sorry no go :joy:

$ npm update bucklescript-tea

+ bucklescript-tea@0.6.2
updated 1 package in 3.121s  

$ npm run build

...
File "overbots/src/overbots.ml", line 1:
Error: The files /Users/bartosz/Documents/OCaml/overbots/node_modules/bucklescript-tea/lib/ocaml/tea.cmi
       and src/overbots_types.cmi make inconsistent assumptions
       over interface Tea
...

I think I’ll give it a try maybe next year :slight_smile: Learn me more pure OCaml maybe first, then try Bucklescript again :confused:

When you update a library with breaking changes you have to ‘clean’ the world so you can make it again. ^.^

That is an OCaml’ism, guess I should add a check to the script to auto-clean or something. ^.^

1 Like

Ok, for anyone interested in writing Bucklescript in vs-code or atom and hae working merlin linitng, you have to install ocaml like it’s written here: https://github.com/BuckleScript/bucklescript/blob/master/site/docsource/Installation.adoc#recommended-installation-with-opam and make sure you have merlin version lesser than 3.0 which on osx mean:

brew install opam
opam switch 4.02.3+buckle-master
eval `opam config env`
opam install merlin.2.5.5

Don’t try installing other versions of ocaml or merlin… it simply won’t work. I spent about 10-12 hours trying to make it work, the above is the only way to make it work witch vs-code and/or atom ¯\_(ツ)_/¯

1 Like