You have to specify them if they are carried from a higher scope. The ‘call’ point does not need to be specified, which OCaml will match in succinctness when the Implicit Modules PR lands (and even right now it’s only a single extra token, so big whoop).
And yes I’m assuming putting in type declarations, Haskell definitely follows the pattern of declaring the types on every declaration because it’s inferring process can be crazy slow otherwise in complex code.
Oooo, interesting, quick reading…
It looks like SML’s modules, simple polymorphic types, no higher polymorphic types (which is what OCaml’s supports). So it is basically just a genericable module system, no HPT’s still.
OCaml is BIG on purity, I’m not sure why you would think otherwise? OCaml does have escapes out of it though, it basically follows how Erlang/Elixir do it, use purity everywhere possible, but be able to break out of it easily (like to write to a file) to Get Real Work Done without writing pages of extra code. Both OCaml and Erlang were birthed from a place of needing to do Real Work, and the languages reflect that, where Haskell was birthed as an interesting research project in comparison so it is interesting to use but not near as practical to get work done as OCaml or Erlang or so. ^.^;
And the typing of operators sucks sure, but you can easily redefine them, or when Implicit Modules comes out then you can just make implicit +
's that work on any types that have modules defined for the functions of that type.
Though currently it is nice that you know what type +.
is by default until you overwrite it, which is always visible in the scope.
Well in OCaml:
type myVariant =
| Thing1
| Thing2 of int
type myStruct = {
something : int;
blah : myVariant;
more : string
} [@@deriving yojson]
let thisIsAStringOfJson =
myStruct_to_yojson {
something = 42;
blah = Thing2 16;
more = "Hello JSON!";
}
let Ok thisIsTheStructBack =
myStruct_of_yojson thisIsAStringOfJson
And you can load a PPX like Yojson into bucklescript, it’s not a drop-in usage like NPM packages are there, but you can always use the OCaml calls directly or an OCaml build system instead.
Plus Bucklescript is not the only OCaml → Javascript engine, js_of_ocaml is an older one, though it’s output javascript code tends to be more unreadable, however it can easily convert about any OCaml code without always needing the source (I don’t think it ever needs the source actually, it converts from the bytecode step, not the AST, which is why it is more unreadable but more powerful), where Bucklescript always needs the source.
I LOVE how fast OCaml compiles, even faster than the dynamic languages of Elixir/Erlang. ^.^
Very fast code at that.