简体   繁体   中英

How to compile f# fable code to a multiple parameter javascript function

Hi I am attempting to make som rudimentary bindings for a database written in java, which ideally I would want to actually use in F#. However I am fairly unfamiliar with javascript. I have managed to get the binding to work with 1 argument however multiple arguments crashes the program due to trying to call a function with 1 argument when you need 3.

The code:

type IRNCouchDBs =
    abstract member Add : string*string*((string)->string)

[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative

Add in this case is in java and is essentially:

@ReactMethod 
public void Add (String name, String type, Callback cb)

if I call the f# code like so

 let str (s : string)  =  s //just a test function
couchDB.Add ("name", "type", (str "test"))

then the error occurs which complains that I am trying to pass a 1 argument function into a multiple argument function.

Any ideas how to solve this would be most appreciated.

I figured it out, fairly obvious in retrospect.

type IRNCouchDBs =
    abstract member Add : Func<string, string, ((string*string->string)), unit>

[<Import("CouchDB", from = "NativeModules")>]
let couchDB : IRNCouchDBs = jsNative


let f' = (fun (x :string,y ) -> (x + y))
couchDB.Add.Invoke (fish.FishType,fish.Name, f')

Used Func, and invoked it which seems to be the way to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM