Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F#函数的通用版本导致IL无效?_F#_Mono_Generics_Il - Fatal编程技术网

F#函数的通用版本导致IL无效?

F#函数的通用版本导致IL无效?,f#,mono,generics,il,F#,Mono,Generics,Il,因此,我编写了一个小的二进制搜索函数(不是我需要的,而是因为我可以),当我将它特定于字符串或整数时,它工作得很好。当我尝试使用泛型类型签名时,就会出现异常 使用泛型类型'A的函数副本: let search (needle : 'a) (haystack: 'a array) : int = let length = Array.length haystack if Array.length haystack <= 0 then -1 else

因此,我编写了一个小的二进制搜索函数(不是我需要的,而是因为我可以),当我将它特定于字符串或整数时,它工作得很好。当我尝试使用泛型类型签名时,就会出现异常

使用泛型类型
'A
的函数副本:

let search (needle : 'a) (haystack: 'a array) : int = 
    let length = Array.length haystack

    if Array.length haystack <= 0
    then -1
    else
        let bottom = 0
        let top = Array.length haystack - 1

        let rec search' (needle : 'a) (haystack: 'a array) (bottom:int) (top:int) : int = 
            if bottom = top
            then if needle = haystack.[top] then top else -1
            else
                let middle = (uint32 top + uint32 bottom) >>> 1 |> int  // avoid an overflow

                if needle <= haystack.[middle]
                then search' needle haystack bottom middle
                else search' needle haystack (middle+1) top

        search' needle haystack bottom top 
let search(针:'a)(草堆:'a数组):int=
let length=Array.length草垛
如果Array.length haystack这对我有效(在.NET 4.0上运行FSI)。也许是单声道bug?

单声道bug。 以前,我有一段代码不能在
fsi
上运行,但可以编译


编辑:已确认该代码不适用于
fsi
,但适用于由
fsc

编译的代码。嗯,是的,通过运行菜单从MonoDevelop运行时必须使用
fsc
,因为这样可以…在此处记录错误:。值得一提的是,bug出现在“Reflection.Emit”(fsi使用的路径)中,而不是Mono编译器本身。我明天会再试一次,但是现在bugzilla.novell.com不存在。你使用的是什么版本的Mono?Mono 2.8…2.6.7版中修复了一些类似的bug。。。(很明显,即使是Ubuntu11.04现在也包括了2.6.7,我现在在10.10中。)嗯。
System.InvalidProgramException: Invalid IL code in FSI_0019:search'@921-13<a> (a,a[],int,int): IL_0000: br        IL_0005
  at FSI_0019.search[String] (System.String needle, System.String[] haystack) [0x00000] in <filename unknown>:0 
  at <StartupCode$FSI_0023>.$FSI_0023.main@ () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
Stopped due to error