*cough*, fixed. ^.^
I plan more things, next article will be on bucklescript-tea once Bucklescript does its new release (probably next week) since that will add remote bsb library support (which is what my library is). ^.^
*cough*, fixed. ^.^
I plan more things, next article will be on bucklescript-tea once Bucklescript does its new release (probably next week) since that will add remote bsb library support (which is what my library is). ^.^
I’m really enjoying your blog combined with http://lambdafoo.com/blog/2015/05/15/unreliable-guide-to-ocaml-modules/ (it’s right at my level I think).
I noticed that all of the javascript code uses var
, whereas I am personally using let
because of my scoping intuitions (I’ve only been doing javascript seriously for a little over a year now and love ES6). In this issue, they mention that they are handling the scoping well. Have you noticed any issues on any non-trivial code? There is also this other issue that mentions let
and scoping as well in failing code. It’s a minor thing, but I’m still wanting to slowly start switching over to Bucklescript/TEA, since the more I see OCaml, the more I like the OO-ish Modules + Functional combination (much like I the BEAM(!)'s architecture on the backend with processes + functions).
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.
It would fit very well on the BEAM too, the segmented process style of the BEAM would fix OCaml’s multi-thread woe’s.
Well, there’s alpaca out there. I’m pretty sure you could be a great contributor to the project.
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.
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 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 http://codeloveandboards.com/blog/2017/02/02/phoenix-and-elm-a-real-use-case-pt-1/ 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