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/
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.
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.
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).
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.
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 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.
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…
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.
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
I followed directly @OvermindDL1’s tutorial Bucklescript-Tea Game OverBots Pt.1 - Setup | Hyperglot Programmer
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
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.
@OvermindDL1 Sorry no go
$ 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 Learn me more pure OCaml maybe first, then try Bucklescript again
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. ^.^
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 ¯\_(ツ)_/¯
Wow there’s a version 3? That’s gotta be new. ^.^
Mine is only:
$ ocamlmerlin -version
The Merlin toolkit version 2.5.0, for Ocaml 4.03.0
I’ve just spend the last week familiarizing myself with bucklescript. So far I’ve encountered several pain points:
-
The Reason syntax seems to be preferred by the community. I tried bucklescript to get better at OCaml, but most libraries (e.g. bindings, such as one listed in reasonml-community org) are written in Reason. It’s a pain to context-switch between the two, as Reason drifts further and further away from OCaml syntax. Reason-tools help in the browser, but that’s extra effort needed for each file in the codebase. I started to feel kind of like a douche that doesn’t want to “fit into” the community by consciously using different syntax.
-
The docs are rather on the incomplete side and community examples are still rare. I’ve had a hard time trying to write bindings for Chrome Extension API, mainly determining what types should I use for the external declarations and how to deal with optional args. I also have no idea whatsoever on how to utilize, for example,
Js.Promise
, and digging the BS source was confusing, I can’t seem to find the definitions of the included modules. -
Is it possible for Bucklescript to output single file from multiple sources, just like how elm-make does it? Or do we need to introduce e.g. Rollup for that? So far the compilation outputs many files with
requires
. I’m not keen on setting up another bundler, having touched them in my JS endeavors can’t say I liked them. -
One time I forgot to switch to
4.02.3+buckle-master
and I had no idea why my merlin integrations did not work. I ended up coding in darkness, and having to inspect the compiler and JS output closely. -
The compiler messages are not too helpful. I’ve got tons of “Syntax Error on file x line y”-ish messages, mainly when I was dealing with point 4. This might be an OCaml problem, though. But I’ve written OCaml before and the errors didn’t seem to be this confusing. BetterErrors installation page recommend installing reason-cli which I don’t see the reason to if I don’t want to use Reason, which brings me back to point 1.
I realize that many of these things could be solved by asking in the Discord (that’s their preferred channel), but I’m the type of person who don’t really enjoy real-time communications such as chat platform or IRC. I’d prefer a more asynchronous method of communication…
As for the docs and examples problems, I completely understand that it most likely are a problem of manpower. But still it kinda hurts the initial jump. I’d like to help, but I feel like the resources to get the beginner me into the context where I could do anything meaningful are still not there yet.
Overall it took more than i guess 24 hours of recompilation, debugging and tears to finally make understand that i need that particular ocaml version to make it work
Actually all you really need is
opam install BetterErrors
And then instead od bsb -make-world
for building do that bsb -make-world 2>&1 | berror
And an example output:
[1/1] Building src/overbots.cmj /Users/bartosz/Documents/OCaml/overbots/lib/es6/src/overbots.js src/overbots.cmi
FAILED: src/overbots.cmj /Users/bartosz/Documents/OCaml/overbots/lib/es6/src/overbots.js src/overbots.cmi
/Users/bartosz/Documents/OCaml/overbots/node_modules/bs-platform/bin/bsc.exe -bs-package-name overbots -bs-package-output es6:lib/es6/src -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include -I /Users/bartosz/Documents/OCaml/overbots/node_modules/bucklescript-tea/lib/ocaml -I src -nostdlib -I '/Users/bartosz/Documents/OCaml/overbots/node_modules/bs-platform/lib/ocaml' -no-alias-deps -color always -w -40+6+7+27+32..39+44+45 -o src/overbots.mlast -c src/overbots.mlast
/Users/bartosz/Documents/OCaml/overbots/src/overbots.ml:8 4-8
5 ┆ let model = {
6 ┆ notUsedYet = 42;
7 ┆ resource_values = 1.0;
8 ┆ msgs;
9 ┆ bool_flags;
10 ┆ int_flags;
11 ┆ } in
Error: `msgs` can't be found. Could it be a typo?
Don’t mind the code it’s just the example of an erorr.
I wouldn’t mind trying to write reason instead of ocaml, but I really don’t like some of reason’s syntax like ==
instead of =
or let list = [hd, ...tl];
instead of let list = hd :: tl
← this ...
particulary bugs me. And the most dreadful one, instead of this let x a b = e
you get let x a b => e;
On the other hand reason’s type pairList = list (int, int);
is a bit more readable at first glance for me than type pairList = (int * int) list
Maybe it all boils down to familiarity with one syntax over the other, because I always hated JS and tended to run from it whenever I could. Both Reason and Bucklescript are still young, so I guess I’ll give it a try to reason for now, because I don’t think I’ll ever write in OCaml, as there are really some pain points with it, and I fell in love with Rust lately.
Update: I found another annoyance in Reason
Ocaml:
let init_int_flags =
let open IntFlagMap in
empty
|> add NoIntFlagsYet 0
Reason
let init_int_flags =
IntFlagMap.(empty |> add NoIntFlagsYet 0);
There is no let in
syntax in Reason
Another Update:
refmt
is tool for formatting reason code. But so far it has same stupid disadvantage as gofmt
has. It is not configurable, it takes input and spits output formatted with whatever insane rules someone at facebook devised.
For example
let all_resources =
let open ResourceMap in
empty
|> add Energy (module Energy : Resource)
|> add IronOxide (module IronOxide : Resource)
|> add RawSilicon (module RawSilicon : Resource)
get’s formatted into incomprehensible at first sight blob of code
let all_resources =
ResourceMap.(
empty |> add Energy ((module Energy): (module Resource)) |>
add IronOxide ((module IronOxide): (module Resource)) |>
add RawSilicon ((module RawSilicon): (module Resource))
);
I’m talking here about pipe operators. But there’s open issue int the github reasons repo so it may be, hopefully, changed.
@bobbypriambodo I had very messy system now after reinstalling all those ocaml’s and nodejs’es so in short
-
opam install BetterErrors
install rather old version - to install fresher version you need to do
opam pin add BetterErrors https://github.com/chenglou/BetterErrors.git#npm-1.2.0
- There is even newer version of code, written in reason, not vanilla ocaml in master branch, but it won’t compile due to missing files
OpamSystem.File_not_found("/Users/bartosz/.opam/4.02.3/build/BetterErrors.0.0.1/pkg/META.in")
but i forked this repo, and try to come with some sane solution tomorrow… maybe - The actuall command is not
bsb -make-world 2>&1 | berror
but ratherbsb -make-world 2>&1 | huh
because when you install it through opam it’s binary name ishuh
and when you install it with reason-cli it’sberror
Sorry for my earlier wrong command, it was due to the mess in my system after reinstalling so many times ocaml and reason through different methods.