Guest User

dPyroc BuckleScript Contribution 1018 words

a guest
Mar 4th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. Here’s a naive example to demonstrate the capabilities of BuckleScript:
  2. The following OCaml code:
  3. Generates the following output code:
  4. BuckleScript Immutable Map:
  5. Facebook Immutable Map:
  6. We also compare code Size:
  7. How is it faster than hand-written JS code?
  8. 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
  9. Arrays are faster for most operations when compared to objects.
  10.  
  11. Other optimizations like <0>tail call conversion</0>, inline and <1>constant propagation</1> are also introduced.
  12. How does it reduce generated code size?
  13. API
  14. Blog
  15. Github
  16. Intro
  17. Interop
  18. Build System
  19. Standard Library
  20. Built With BuckleScript
  21. Help Translate
  22.  
  23. This is an uncurried bucklescript function. It must be applied with.
  24. Fast Iteration Loop
  25. Null, Undefined &; Option
  26.  
  27. Reason syntax:
  28. To create a nullable string, do:
  29. Reason syntax:
  30. No more nullable bugs!
  31. converts from a to does the opposite.
  32. The helper module is here
  33. Tips &; Tricks
  34. Forum
  35. Stack Overflow
  36. Reason Syntax
  37. Output:
  38. Reason Syntax
  39. Output:
  40. Reason Syntax
  41. Albeit the names are called and, it's really dynamic access of objects fields and/or arrays.
  42. Output:
  43. Specific Getter/ Setter
  44.  
  45. Reason Syntax
  46. Output:
  47. Improve this documentation site at
  48. BuckleScript core contribution guide is here
  49. Suggest better error messages for BuckleScrip
  50. array. [high, low]. high is signed, low unsigned
  51. char
  52. bytes
  53. number array (we might encode it as buffer in NodeJS)
  54. registro
  55. array
  56. option
  57. list
  58. Variant
  59. Polymorphic variant
  60. exception
  61. extension
  62. object
  63. Explanation: by default, your files, once used as a third-party dependency, are available globally to the consumer.
  64. E.g. if you have an <code>Util.re</code> and the consumer also has a file of the same name, they will clash.
  65. Turning on avoids this by wrapping all your own project's f
  66. iles into an extra module layer; instead of a global module, the consumer will see you as The namespacing affects your consumers, not yourself.
  67. We don't do folder-level namespacing for your own project; all your own file names must be unique.
  68. This is a constraint that enables several features such as fast search and easier project reorganization.
  69. In an external, you can directly convert a into an through:
  70. Reason Syntax
  71. Reason Syntax
  72. Output:
  73. For example, think of the difference of use-case and intent between the object and.
  74. Accesors
  75. Read
  76. To access a field, use
  77.  
  78. Reason Syntax
  79. Reason Syntax
  80. Why
  81. Reason Syntax
  82. You can use <code>[%bs.obj putAnOCamlRecordHere]</code> DSL to create a JS object:
  83. Reason Syntax
  84. The created object will have an inferred type, no type declaration needed!
  85. The above example will infer as
  86.  
  87. Reason Syntax
  88. Info
  89. Reason Syntax
  90. access them as objects
  91. Output:
  92. Nota
  93. Reason Syntax
  94. Output:
  95. Name mangling
  96. Extra flags to pass to the underlying call.
  97. Notably: for turning on cleaning error output
  98. No need to pass this flag for a Reason project; it's enabled by default.
  99. Overview
  100. Add to keep the built-in watcher running. Any new file change will be picked up and the build will re-run.
  101. Note: third-party libraries (in) aren't watched, as doing so may exceed the watcher count limit.
  102. If you're doing quick and dirty modifications inside, you have to do to rebuild them.
  103. To build only yourself, use
  104. to see all the available options.
  105.  
  106. If you ever get into a stable build for edge-case reasons, use:
  107. Or to clean only your own artifacts.
  108. Bsb generates a file, used by various editor plugins under the hood to power e.g. autocomplete, type hint, diagnosis, etc.
  109. Bonus: you can directly pipe the bsb terminal error messages into VSCode by setting the config here
  110. A typical problem with traditional build systems is that they're not resilient against the user moving/ deleting source files.
  111. Most don't clean up the old artifacts correctly after such user action\*.
  112. 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.
  113. One such build system that tracks these correctly &; efficiently is Tup.
  114. See the (rather accessible!) paper here
  115. Unfortunately, Tup's implementation uses FUSE and other systems, which we can't safely use on every platform.
  116. disallowed! Don't access the object's internal details
  117. disallowed! Don't access the object's internal details
  118. received something wrong from the JS side
  119. received something wrong from the JS side
  120. nope, can't take a random int
  121. nope, can't take a random int
  122. int
  123. number
  124. nativeint
  125. number
  126. number
  127. float
  128. number
  129. string
  130. string
  131. array
  132. array
  133. tuple
  134. array
  135. Boolean
  136. Object
  137. Bool
  138. Not found
  139. Not found
  140. Main
  141. Hello
  142. Hello
  143. Hello
  144. Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE
  145. Hello
  146. Not a pure module
  147. Hello
  148. World
  149. How
  150. Are
  151. You
  152. Hello
  153. World
  154. How
  155. Are
  156. You
  157. Hello
  158. World
  159. How
  160. Are
  161. You
  162. border is optional, defaults to false
  163. abstract type for a document object
  164. abstract type for a document object
  165. Drawing
  166. Drawing
  167. Drawing
  168. Drawing
  169. Drawing
  170. Drawing
  171. Draw
  172. Draw
  173. Draw
  174. Number
  175. Expected string or number, got
  176. Hello World
  177. Hello World
  178. Message from BS:
  179. Hello World
  180. Hello World
  181. Message from BS:
  182. Hello World
  183. Hello World
  184. Message from BS:
  185. Exit
  186. Error code:
  187. Exit
  188. Error code:
  189. Exit
  190. Error code
  191. Hello
  192. Hello
  193. Generators
  194. name
  195. command
  196. sources
  197. generators
  198. name
  199. the value you've gotten here
  200. the value you've gotten here
  201. hello
  202. hello
  203. Tada!
  204. is documented in the class section
  205. is documented in the class section
  206. name
  207. name
  208. name
  209. name
  210. Submit of string
  211. Cancel
  212. Submit string
  213. Cancel
  214. Submit
  215. Cancel
  216. Hello
  217. gives Submit "hello"
  218. hello
  219. gives Submit "hello"
  220. assignment is optional
  221. or whatever module system your project uses
  222. sources
  223. examples
  224. sources
  225. page
  226. sources
  227. examples
  228. recursively builds every subdirectory
  229. Accountant
  230. Name
  231. Age
  232. Job
  233. Accountant
  234. Open
  235. Open
  236. Hello world
  237. Hello world
  238. Why bucklescript matters for javascript platform
  239. hello from raw JavaScript
  240. hello from raw JavaScript
  241. dev mode
  242. production mode
  243. dev mode
  244. production mode
  245. undefined
  246. dev mode
  247. production mode
  248. undefined
  249. non node environment
  250. non node environment
  251. undefined
  252. non node environment
  253. Apple
  254. Orange
  255. Kiwi
  256. Watermelon
  257. Apple
  258. Orange
  259. Kiwi
  260. Watermelon
  261. Apple
  262. Orange
  263. Kiwi
  264. Watermelon
  265. Apple
  266. Orange
  267. Kiwi
  268. Watermelon
  269. Apple
  270. This is Kiwi
  271. Apple
  272. Kiwi
  273. Watermelon
  274. Apple
  275. Kiwi
  276. Watermelon
  277. Apple
  278. Kiwi
  279. Watermelon
  280. Apple
  281. I Swear This Is A Kiwi
  282. Apple
  283. Kiwi
  284. Watermelon
  285. Apple
  286. I Swear This Is A Kiwi
  287. Apple
  288. Kiwi
  289. Minicoconut
  290. Watermelon
  291. Apple
  292. Apple
  293. Kiwi
  294. Minicoconut
  295. Apple
  296. miniCoconut
  297. Kiwi
  298. Watermelon
  299. Apple
  300. Apple
  301. Kiwi
  302. Minicoconut
  303. hello
  304. wrong
  305. wrong
Advertisement
Add Comment
Please, Sign In to add comment