简体   繁体   English

如何将 f# fable 代码编译为多参数 javascript 函数

[英]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#.嗨,我正在尝试为用 java 编写的数据库制作一些基本绑定,理想情况下我希望在 F# 中实际使用。 However I am fairly unfamiliar with javascript.但是我对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.我设法使绑定与 1 个参数一起工作,但是由于在需要 3 个参数时尝试调用具有 1 个参数的函数,因此多个参数使程序崩溃。

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:添加在这种情况下是在 java 中,本质上是:

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

if I call the f# code like so如果我像这样调用 f# 代码

 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.然后发生错误,它抱怨我试图将一个 1 参数函数传递给一个多参数函数。

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.使用 Func,并调用它,这似乎是这样做的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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