int -> Funscript 中的字符串转换?
int -> string conversion in Funscript?
我刚开始使用 Funscript,一开始就遇到了一些错误。
在编写 F# 时,我通常将整数转换为字符串,如下所示:
let str = string 123
运行时出现以下错误:
Ohanterat undantag: System.Exception: Could not compile expression: Call (None, ToString, [Value (123)])
vid FunScript.InternalCompiler.clo@117-1.Invoke(String message)
vid Microsoft.FSharp.Core.PrintfImpl.go@523-3[b,c,d](String fmt, Int32 len, FSharpFunc`2 outputChar, FSharpFunc`2 outa, b os, FSharpFunc`2 finalize, FSharpList`1 args, Int32 i)
vid Microsoft.FSharp.Core.PrintfImpl.run@521[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args)
vid Microsoft.FSharp.Core.PrintfImpl.capture@540[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args, Type ty, Int32 i)
vid <StartupCode$FSharp-Core>.$Reflect.Invoke@720-4.Invoke(T1 inp)
vid FunScript.CompilerComponent.splitDeclarationFromUsageIfNeeded(ICompiler compiler, FSharpExpr expr)
vid FunScript.CompilerComponent.makeFriendly@28.Invoke(a expr)
vid FunScript.LetBindings.binding@9-1.Invoke(FSharpExpr _arg1)
vid FunScript.CompilerComponent.create@32.FunScript-InternalCompiler-ICompilerComponent-TryCompile(ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.tryComponent(IReturnStrategy returnStategy, FSharpExpr expr, ICompilerComponent part)
vid FunScript.InternalCompiler.result@76.Invoke(ICompilerComponent part)
vid Microsoft.FSharp.Collections.ListModule.TryPick[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list)
vid FunScript.InternalCompiler.Compiler.tryAllComponents(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.compile(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.ReflectedDefinitions.genMethod(MethodBase mb, MethodBase replacementMi, FSharpList`1 vars, FSharpExpr bodyExpr, FSharpVar var, ICompiler compiler)
vid FunScript.ReflectedDefinitions.createGlobalMethod@49.Invoke(FSharpVar var)
vid FunScript.InternalCompiler.Compiler.define(String name, FSharpFunc`2 cons)
vid FunScript.InternalCompiler.Compiler.FunScript-InternalCompiler-ICompiler-DefineGlobal(String name, FSharpFunc`2 cons)
vid FunScript.ReflectedDefinitions.createGlobalMethod(String name, ICompiler compiler, MethodBase mb, CallType callType)
vid FunScript.ReflectedDefinitions.createCall[a](FSharpFunc`2 |Split|, IReturnStrategy returnStategy, ICompiler compiler, IEnumerable`1 exprs, MethodInfo mi)
vid FunScript.ReflectedDefinitions.methodCalling@209.Invoke(FSharpFunc`2 split, ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr _arg1)
vid FunScript.CompilerComponent.create@32.FunScript-InternalCompiler-ICompilerComponent-TryCompile(ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.tryComponent(IReturnStrategy returnStategy, FSharpExpr expr, ICompilerComponent part)
vid FunScript.InternalCompiler.result@76.Invoke(ICompilerComponent part)
vid Microsoft.FSharp.Collections.ListModule.TryPick[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list)
vid FunScript.InternalCompiler.Compiler.tryAllComponents(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.compile(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.Compiler.Compiler.Compile(FSharpExpr expression, FSharpOption`1 components, FSharpOption`1 noReturn, FSharpOption`1 shouldFlattenGenericsForReflection)
vid <StartupCode$FunScript-Test>.$Program.main@() i C:\Users\Andreas\Desktop\funscript\WebGL\WebGL\Program.fs:rad 42
我知道我可以改为 123.ToString(),但我想知道这是否根本没有实现或者我应该向 Funscript github 页面报告的错误。
使用 VS2013 Update 4 和来自 NuGet 的最新 Funscript。
这看起来像是 FunScript 中的错误(即缺少应该存在的映射),所以如果您可以在 GitHub 上提交错误报告,那就太好了。 (我不确定这里出了什么问题,因为源代码中有is a mapping for string
。
无论如何,FunScript 无法翻译所有内容,您始终可以添加自定义函数来提供您缺少的功能,因此您可以将类似的内容添加到您的项目中(直到问题得到解决):
[<JSEmit("return String({0});")>] // Inline JS code for converting to strings
let string (v:'TAny) : string = // The function is never executed so we can just
failwith "JavaScript mapping is never executed" // throw an exception here!
我刚开始使用 Funscript,一开始就遇到了一些错误。
在编写 F# 时,我通常将整数转换为字符串,如下所示:
let str = string 123
运行时出现以下错误:
Ohanterat undantag: System.Exception: Could not compile expression: Call (None, ToString, [Value (123)])
vid FunScript.InternalCompiler.clo@117-1.Invoke(String message)
vid Microsoft.FSharp.Core.PrintfImpl.go@523-3[b,c,d](String fmt, Int32 len, FSharpFunc`2 outputChar, FSharpFunc`2 outa, b os, FSharpFunc`2 finalize, FSharpList`1 args, Int32 i)
vid Microsoft.FSharp.Core.PrintfImpl.run@521[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args)
vid Microsoft.FSharp.Core.PrintfImpl.capture@540[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args, Type ty, Int32 i)
vid <StartupCode$FSharp-Core>.$Reflect.Invoke@720-4.Invoke(T1 inp)
vid FunScript.CompilerComponent.splitDeclarationFromUsageIfNeeded(ICompiler compiler, FSharpExpr expr)
vid FunScript.CompilerComponent.makeFriendly@28.Invoke(a expr)
vid FunScript.LetBindings.binding@9-1.Invoke(FSharpExpr _arg1)
vid FunScript.CompilerComponent.create@32.FunScript-InternalCompiler-ICompilerComponent-TryCompile(ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.tryComponent(IReturnStrategy returnStategy, FSharpExpr expr, ICompilerComponent part)
vid FunScript.InternalCompiler.result@76.Invoke(ICompilerComponent part)
vid Microsoft.FSharp.Collections.ListModule.TryPick[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list)
vid FunScript.InternalCompiler.Compiler.tryAllComponents(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.compile(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.ReflectedDefinitions.genMethod(MethodBase mb, MethodBase replacementMi, FSharpList`1 vars, FSharpExpr bodyExpr, FSharpVar var, ICompiler compiler)
vid FunScript.ReflectedDefinitions.createGlobalMethod@49.Invoke(FSharpVar var)
vid FunScript.InternalCompiler.Compiler.define(String name, FSharpFunc`2 cons)
vid FunScript.InternalCompiler.Compiler.FunScript-InternalCompiler-ICompiler-DefineGlobal(String name, FSharpFunc`2 cons)
vid FunScript.ReflectedDefinitions.createGlobalMethod(String name, ICompiler compiler, MethodBase mb, CallType callType)
vid FunScript.ReflectedDefinitions.createCall[a](FSharpFunc`2 |Split|, IReturnStrategy returnStategy, ICompiler compiler, IEnumerable`1 exprs, MethodInfo mi)
vid FunScript.ReflectedDefinitions.methodCalling@209.Invoke(FSharpFunc`2 split, ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr _arg1)
vid FunScript.CompilerComponent.create@32.FunScript-InternalCompiler-ICompilerComponent-TryCompile(ICompiler compiler, IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.tryComponent(IReturnStrategy returnStategy, FSharpExpr expr, ICompilerComponent part)
vid FunScript.InternalCompiler.result@76.Invoke(ICompilerComponent part)
vid Microsoft.FSharp.Collections.ListModule.TryPick[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list)
vid FunScript.InternalCompiler.Compiler.tryAllComponents(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.InternalCompiler.Compiler.compile(IReturnStrategy returnStategy, FSharpExpr expr)
vid FunScript.Compiler.Compiler.Compile(FSharpExpr expression, FSharpOption`1 components, FSharpOption`1 noReturn, FSharpOption`1 shouldFlattenGenericsForReflection)
vid <StartupCode$FunScript-Test>.$Program.main@() i C:\Users\Andreas\Desktop\funscript\WebGL\WebGL\Program.fs:rad 42
我知道我可以改为 123.ToString(),但我想知道这是否根本没有实现或者我应该向 Funscript github 页面报告的错误。
使用 VS2013 Update 4 和来自 NuGet 的最新 Funscript。
这看起来像是 FunScript 中的错误(即缺少应该存在的映射),所以如果您可以在 GitHub 上提交错误报告,那就太好了。 (我不确定这里出了什么问题,因为源代码中有is a mapping for string
。
无论如何,FunScript 无法翻译所有内容,您始终可以添加自定义函数来提供您缺少的功能,因此您可以将类似的内容添加到您的项目中(直到问题得到解决):
[<JSEmit("return String({0});")>] // Inline JS code for converting to strings
let string (v:'TAny) : string = // The function is never executed so we can just
failwith "JavaScript mapping is never executed" // throw an exception here!