Skip to content

Commit 34954e5

Browse files
committed
Shorten faq
1 parent b4bebc0 commit 34954e5

1 file changed

Lines changed: 7 additions & 75 deletions

File tree

docs/faq.md

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
title: Frequently Asked Questions
33
---
44

5-
### Should I learn Reason or OCaml first?
6-
There's no need to pick! Reason and OCaml share the exact same semantics (i.e. how the code runs). Only the syntax differ. Carry [Reason-tools](https://github.com/reasonml/reason-tools) around so that you can freely convert between the two syntaxes. A Reason tutorial is an OCaml tutorial, vice-versa. In the terminal, you can have these aliases:
7-
8-
```sh
9-
# converts ocaml code into reason
10-
alias mlre="pbpaste | refmt --parse ml --print re --interface false | pbcopy"
11-
# converts reason code into ocaml
12-
alias reml="pbpaste | refmt --parse re --print ml --interface false | pbcopy"
13-
```
14-
15-
They'll take your code from the (macOS) clipboard, convert it, and paste it back into your clipboard! Swap out pbpaste/pbcopy with your system's clipboard functions.
16-
175
### I'm not sure what to do with Reason
186
Think of what project you'd usually make if it was pure JavaScript; try porting/writing that in Reason + BuckleScript instead! We recommend trying to make concrete, end-user projects (e.g. a little command line util) rather than infra-level projects (e.g. a boilerplate generator). The latter category requires expertise and understanding idiomatic Reason code.
197

@@ -28,23 +16,21 @@ You can read more about the Pervasives library in the api documentation:
2816
https://reasonml.github.io/api/Pervasives.html
2917

3018
### Can I have a function to print arbitrary data structures?
31-
If you're compiling to JavaScript through BuckleScript, you can use the JS `console.log` through [`Js.log`](https://bucklescript.github.io/bucklescript/api/Js.html#VALlog). If you're compiling to native, you'll need something like [ppx_show](https://github.com/diml/ppx_show). A future OCaml feature (called modular implicit) will solve this directly in the language.
19+
If you're compiling to JavaScript through BuckleScript, you can use the JS `console.log` through [`Js.log`](https://bucklescript.github.io/bucklescript/api/Js.html#VALlog).
3220

3321
### Why is there a + for adding ints and +. for adding floats, etc.?
3422
See [here](integer-and-float.md#design-decisions).
3523

3624
### Does library ___ work with Reason?
37-
Most JS libraries should easily work under Reason + BuckleScript. On the native side, since Reason's just a syntax transform: yes, they work with Reason too. But the native workflow is currently work-in-progress and needs polish.
25+
Most JS libraries should easily work under Reason + BuckleScript.
3826

3927
### What's the server-side story? Should I compile to native or to JS and use node.js?
40-
We do compile to native, but the native workflow is currently work-in-progress. At this time, we recommend compiling to JS through BuckleScript and use the JS wrappers at [reasonml-community](https://github.com/reasonml-community) or somewhere else.
28+
At this time, we recommend compiling to JS through BuckleScript and use the JS wrappers at [reasonml-community](https://github.com/reasonml-community) or somewhere else.
4129

4230
### What's BuckleScript's async story?
43-
First, if you're not interfacing with any library that uses promises, you can simply use callbacks. Everyone gets them and they're performant.
31+
If you're not interfacing with any library that uses promises, you can simply use callbacks. Everyone gets them and they're performant.
4432

45-
If you need to bind to a JS library that uses promises, or communicate with such library, you can use BS's [Js.Promise](http://bucklescript.github.io/bucklescript/api/Js.Promise.html). There's also potential to have some syntactic sugar in the future. In the long run, we'd like to implement a spec-compliant promises implementation in OCaml/Reason proper, so that the compiler optimizations could kick in.
46-
47-
For a more idiomatic OCaml solution: on the native OCaml side, we have [lwt](http://ocsigen.org/lwt/) and [Async](https://ocaml.janestreet.com/ocaml-core/111.03.00/doc/async/#Std). We don't use them in web right now, but we might in the future.
33+
If you need to bind to a JS library that uses promises, or communicate with such library, you can use BS's [Js.Promise](http://bucklescript.github.io/bucklescript/api/Js.Promise.html).
4834

4935
### What's the (unit) test story?
5036
Some of OCaml's language features (not just types) might be able to defer the need for unit testing until later. In the meantime, for compilation to JS, we're working on [Jest wrapper](https://github.com/BuckleTypes/bs-jest). We'll look into using Jest for native too, if Jest is written using Reason in the future (no concrete plan yet). [OUnit](http://ounit.forge.ocamlcore.org) is a good, small native OCaml testing library right now.
@@ -69,59 +55,5 @@ Assuming `MyModule` is a module's name, `t` is a community convention that indic
6955
### Why is there a [`Js_promise`](http://bucklescript.github.io/bucklescript/api/Js_promise.html) and then a [`Js.Promise`](http://bucklescript.github.io/bucklescript/api/Js.Promise.html)? What about [`Js_array`](http://bucklescript.github.io/bucklescript/api/Js_array.html), [`Js_string`](http://bucklescript.github.io/bucklescript/api/Js_string.html) and whatever else?
7056
As a convention, `Js_foo` is the actual module, and `Js.Foo` is just an alias for it. They're [equivalent](https://github.com/bloomberg/bucklescript/blob/7bc37f387a726ba1ae4afeefe02b9c82577d9e10/jscomp/runtime/js.ml#L124-L138). Prefer `Js.Foo`, because that's the official, public module name.
7157

72-
### When will modular implicit & multicore & algebraic effects be ready?
73-
They will one day. In the meantime, help us ship more Reason code! The popularity will help funnel more OCaml contributions. The less the OCaml folks need to worry about low-hanging fruits, the more they can focus on great research and execution!
74-
75-
### Why are BuckleScript and bsb so fast? How can I slow it down?
76-
BuckleScript is optimized for performance across the whole stack. You can try slowing it down by adding a dozen layers of indirections and metaprogramming. Try:
77-
78-
- Adding a few infinite loops here and there.
79-
- Stuffing a JavaScript build tool in the pipeline.
80-
- Dragging in more dependencies for writing a hello world.
81-
82-
### I'm seeing a weird .cmi/.cmx/.cmj/.cma file referenced in a compiler error. Where do these files come from?
83-
84-
The OCaml community frequently uses file extensions to distinguish between types of source, artifacts, and metadata, depending on your build target (native/bytecode/JavaScript). The following is a overview of some of the file extensions you may come across:
85-
86-
#### Source files
87-
88-
- `.ml`: OCaml source file
89-
- `.mli`: OCaml interface file; determines which parts of the matching `.ml` file are visible to the outside world
90-
- `.re`: Reason source file. Like `.ml`, but for Reason
91-
- `.rei`: Reason interface file. Like `.mli`, but for Reason
92-
93-
#### Compiled files
94-
95-
- `.cmi`: Compiled interface (.rei/mli) file
96-
- `.cmx`: Compiled object file for native output (via ocamlopt)
97-
- `.cmo`: Compiled object file for bytecode output
98-
- `.cmj`: Compiled object file for web (via BuckleScript)
99-
- `.cma`: Library file for bytecode output (equivalent to C's .a files)
100-
- `.cmxa`: Library file for native output
101-
- `.cmt`: Contains a "Typedtree" – basically the AST with all type info
102-
- `.cmti`: Just like a .cmt file, but for interface files
103-
- `.cmxs`: Dynamically loaded plugin (for native compilation)
104-
- `.o`: Compiled native object file
105-
- `.out`: Conventional name/extension for final output produced by ocamlc/ocamlopt (e.g. `ocamlc -o myExecutable.out`)
106-
107-
#### Other OCaml ecosystem files
108-
109-
- `.mll`: ocamllex lexical analyzer definition file
110-
- `.mly`: ocamlyacc parser generator definition file
111-
- `.mldylib`: Contains a list of module paths that will be compiled and archived together to build a corresponding `.cmxs` target (native plugin)
112-
- `.mliv`: Batteries-specific files for some [custom preprocessing](https://github.com/ocaml-batteries-team/batteries-included/blob/f019927b9503ec65ef816f02315de78d4bae3481/src/batArray.mliv).
113-
- `.mllib`: OCaml library (cma and cmxa)
114-
- `.mlpack`: OCaml package (cmo built with the -pack flag)
115-
- `.mlpp`: [Extlib](https://github.com/ygrek/ocaml-extlib)-specific files for some custom preprocessing
116-
- `.mltop`: [OCamlbuild top-level file](https://shonkychef.wordpress.com/2009/07/28/making-an-ocaml-toplevel-with-ocamlbuild/), used by OCamlbuild to generate a .top file
117-
- `.odocl`: OCaml documentation file
118-
119-
If some of those explanations are still a bit cryptic, here are expansions on some of the terms used above:
120-
- [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree): Abstract Syntax Tree. The data structure coming from the source code, that the compiler operates on.
121-
- [Linking](https://en.wikipedia.org/wiki/Linker_(computing)): The step where the compiler takes many intermediate compiled files and assembles them together. E.g. linking A with B, because A's original source file referred to B.
122-
- Native: Builds that run on bare metal assembly instructions of the platform in question.
123-
- [Bytecode](https://en.wikipedia.org/wiki/Bytecode): Like native code, but more portable and less performant
124-
- [Object file](https://en.wikipedia.org/wiki/Object_file): Contains machine code that is not directly runnable.
125-
126-
There is more information and context for many of these file extensions [on the OCaml site](https://ocaml.org/learn/tutorials/filenames.html) and in [this mailing list post](http://caml.inria.fr/pub/ml-archives/caml-list/2008/09/2bc9b38171177af5dc0d832a365d290d.en.html). There are also deeper dives on [native](https://caml.inria.fr/pub/docs/manual-ocaml/native.html) and [bytecode](http://caml.inria.fr/pub/docs/manual-ocaml/comp.html) compilation that contain more detailed descriptions in the OCaml manual.
127-
58+
### Why are BuckleScript and bsb so fast?
59+
Software should at least be this fast.

0 commit comments

Comments
 (0)