这让我很难过.
我已经阅读了关于这个主题的SO帖子:这里是最相关的,但它没有涵盖将代表传递给一个事件(尽管我预计它会很简单).
具体来说,VS中的错误是:
This function value is being used to construct a delegate type whose signature includes a byref argument. You must use an explicit lambda expression taking 2 arguments.
Run Code Online (Sandbox Code Playgroud)
我能找到的错误的最佳推理是在Eric Lippert的博客中,但我认为我已经在下面处理了它.
// Documentation: http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx
// Don't forget to unwrap the instance before using it.
let mutable ieInstance : option<InternetExplorer> = None
let onDocumentComplete (pDisp : Object) (url : byref<Object>) =
let doc = ieInstance.Value.Document :?> IHTMLDocument2
let window = doc.parentWindow
window.execScript(@"alert('Message added by addon.');") |> …Run Code Online (Sandbox Code Playgroud) 我已经编写了该length函数的六个版本。一些性能差异是有道理的,但其中一些似乎根本不同意我读过的文章(例如this one和this one)。
-- len1 and lenFold1 should have equivalent performance, right?
len1 :: [a] -> Integer
len1 [] = 0
len1 (x:xs) = len1 xs + 1
lenFold1 :: [a] -> Integer
lenFold1 = foldr (\_ a -> a + 1) 0
-- len2 and lenFold2 should have equivalent performance, right?
len2 :: [a] -> Integer
len2 xs = go xs 0 where
go [] acc = acc
go (x:xs) acc = go …Run Code Online (Sandbox Code Playgroud)