Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here’s a naive example to demonstrate the capabilities of BuckleScript:
- The following OCaml code:
- Generates the following output code:
- BuckleScript Immutable Map:
- Facebook Immutable Map:
- We also compare code Size:
- How is it faster than hand-written JS code?
- Since there are only two branches in this <0>algebraic data type</0>, will be simply encoded as (with comments for readable output) and will be encoded as
- Arrays are faster for most operations when compared to objects.
- Other optimizations like <0>tail call conversion</0>, inline and <1>constant propagation</1> are also introduced.
- How does it reduce generated code size?
- API
- Blog
- Github
- Intro
- Interop
- Build System
- Standard Library
- Built With BuckleScript
- Help Translate
- This is an uncurried bucklescript function. It must be applied with.
- Fast Iteration Loop
- Null, Undefined &; Option
- Reason syntax:
- To create a nullable string, do:
- Reason syntax:
- No more nullable bugs!
- converts from a to does the opposite.
- The helper module is here
- Tips &; Tricks
- Forum
- Stack Overflow
- Reason Syntax
- Output:
- Reason Syntax
- Output:
- Reason Syntax
- Albeit the names are called and, it's really dynamic access of objects fields and/or arrays.
- Output:
- Specific Getter/ Setter
- Reason Syntax
- Output:
- Improve this documentation site at
- BuckleScript core contribution guide is here
- Suggest better error messages for BuckleScrip
- array. [high, low]. high is signed, low unsigned
- char
- bytes
- number array (we might encode it as buffer in NodeJS)
- registro
- array
- option
- list
- Variant
- Polymorphic variant
- exception
- extension
- object
- Explanation: by default, your files, once used as a third-party dependency, are available globally to the consumer.
- E.g. if you have an <code>Util.re</code> and the consumer also has a file of the same name, they will clash.
- Turning on avoids this by wrapping all your own project's f
- iles into an extra module layer; instead of a global module, the consumer will see you as The namespacing affects your consumers, not yourself.
- We don't do folder-level namespacing for your own project; all your own file names must be unique.
- This is a constraint that enables several features such as fast search and easier project reorganization.
- In an external, you can directly convert a into an through:
- Reason Syntax
- Reason Syntax
- Output:
- For example, think of the difference of use-case and intent between the object and.
- Accesors
- Read
- To access a field, use
- Reason Syntax
- Reason Syntax
- Why
- Reason Syntax
- You can use <code>[%bs.obj putAnOCamlRecordHere]</code> DSL to create a JS object:
- Reason Syntax
- The created object will have an inferred type, no type declaration needed!
- The above example will infer as
- Reason Syntax
- Info
- Reason Syntax
- access them as objects
- Output:
- Nota
- Reason Syntax
- Output:
- Name mangling
- Extra flags to pass to the underlying call.
- Notably: for turning on cleaning error output
- No need to pass this flag for a Reason project; it's enabled by default.
- Overview
- Add to keep the built-in watcher running. Any new file change will be picked up and the build will re-run.
- Note: third-party libraries (in) aren't watched, as doing so may exceed the watcher count limit.
- If you're doing quick and dirty modifications inside, you have to do to rebuild them.
- To build only yourself, use
- to see all the available options.
- If you ever get into a stable build for edge-case reasons, use:
- Or to clean only your own artifacts.
- Bsb generates a file, used by various editor plugins under the hood to power e.g. autocomplete, type hint, diagnosis, etc.
- Bonus: you can directly pipe the bsb terminal error messages into VSCode by setting the config here
- A typical problem with traditional build systems is that they're not resilient against the user moving/ deleting source files.
- Most don't clean up the old artifacts correctly after such user action\*.
- Bsb is unfortunately no different, unless you turn on in, in which case we can track which JS artifact belongs to which source file correctly, even against source file moving/ deletion.
- One such build system that tracks these correctly &; efficiently is Tup.
- See the (rather accessible!) paper here
- Unfortunately, Tup's implementation uses FUSE and other systems, which we can't safely use on every platform.
- disallowed! Don't access the object's internal details
- disallowed! Don't access the object's internal details
- received something wrong from the JS side
- received something wrong from the JS side
- nope, can't take a random int
- nope, can't take a random int
- int
- number
- nativeint
- number
- number
- float
- number
- string
- string
- array
- array
- tuple
- array
- Boolean
- Object
- Bool
- Not found
- Not found
- Main
- Hello
- Hello
- Hello
- Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE
- Hello
- Not a pure module
- Hello
- World
- How
- Are
- You
- Hello
- World
- How
- Are
- You
- Hello
- World
- How
- Are
- You
- border is optional, defaults to false
- abstract type for a document object
- abstract type for a document object
- Drawing
- Drawing
- Drawing
- Drawing
- Drawing
- Drawing
- Draw
- Draw
- Draw
- Number
- Expected string or number, got
- Hello World
- Hello World
- Message from BS:
- Hello World
- Hello World
- Message from BS:
- Hello World
- Hello World
- Message from BS:
- Exit
- Error code:
- Exit
- Error code:
- Exit
- Error code
- Hello
- Hello
- Generators
- name
- command
- sources
- generators
- name
- the value you've gotten here
- the value you've gotten here
- hello
- hello
- Tada!
- is documented in the class section
- is documented in the class section
- name
- name
- name
- name
- Submit of string
- Cancel
- Submit string
- Cancel
- Submit
- Cancel
- Hello
- gives Submit "hello"
- hello
- gives Submit "hello"
- assignment is optional
- or whatever module system your project uses
- sources
- examples
- sources
- page
- sources
- examples
- recursively builds every subdirectory
- Accountant
- Name
- Age
- Job
- Accountant
- Open
- Open
- Hello world
- Hello world
- Why bucklescript matters for javascript platform
- hello from raw JavaScript
- hello from raw JavaScript
- dev mode
- production mode
- dev mode
- production mode
- undefined
- dev mode
- production mode
- undefined
- non node environment
- non node environment
- undefined
- non node environment
- Apple
- Orange
- Kiwi
- Watermelon
- Apple
- Orange
- Kiwi
- Watermelon
- Apple
- Orange
- Kiwi
- Watermelon
- Apple
- Orange
- Kiwi
- Watermelon
- Apple
- This is Kiwi
- Apple
- Kiwi
- Watermelon
- Apple
- Kiwi
- Watermelon
- Apple
- Kiwi
- Watermelon
- Apple
- I Swear This Is A Kiwi
- Apple
- Kiwi
- Watermelon
- Apple
- I Swear This Is A Kiwi
- Apple
- Kiwi
- Minicoconut
- Watermelon
- Apple
- Apple
- Kiwi
- Minicoconut
- Apple
- miniCoconut
- Kiwi
- Watermelon
- Apple
- Apple
- Kiwi
- Minicoconut
- hello
- wrong
- wrong
Advertisement
Add Comment
Please, Sign In to add comment