
Writing ReasonML Bindings for JavaScript APIs - munchor
http://davidgom.es/2017/12/23/reasonml-webworkers-bindings.html
======
k__
The problem I see with the bindings at the moment is, JS uses very different
data structures from Reason, so a simple conversion often doesn't give you the
power pf Reasons type system.

This requires people to bind to JS and then do some runtime-conversion to get
idiomatic Reason out of it.

~~~
hongbo_zhang
Not really. You can model complex js data type as abstract type, and only
provide functions needed

~~~
k__
JS data structures are basically big objects with strings as differntiator.
Reason works with lists, tupels and variants

~~~
yawaramin
And records. You would typically define a record type to do the heavy lifting
in, and do some lightweight conversions to and from JS. Here's an example:

    
    
        [@bs.deriving jsConverter]
        type person = {name: string, age: int};
        
        let bob = {name: "Bob", age: 33};
        let olderBob = {...bob, age: bob.age + 1};
        let () = Js.log(personToJs(olderBob));

~~~
k__
But the records wouldn't use variants.

~~~
yawaramin
Nope, you can definitely use variants in the records. BuckleScript (the
compiler) will automatically convert them into JavaScript-friendly
representations. Or you can also pick custom representations for each variant
case.

~~~
k__
Ah, yes if you only go from Reason to JS, becaue Reason is much richer.

I was thinking about going from a JS library to Reason, where you basically
get bags full of strings.

