I've made some progress here by using a lambda:

1
2
3
4
let erode = erodePixel structuringElement image 

new FastImage(image.Width, image.Height, (fun i j -> erode i j)) :> IImage 

although I don't understand why this makes any difference.

It also seems to work if I directly construct a System.Func instance from erode and pass that to the FastImage constructor.

However, it does not work, with a let binding, even on that explicit accepts two parameters i j removing the partial application in my original example.

The code is working, but I'm still confused. By the way, I'm using the September 2008 CTP version of F#.

Rob

By on 10/26/2008 12:06 PM ()

Offtopic: Anything enclosed in angled brackets in my code samples above (generic type parameters on Func and FastImage) has not come through into the forum posting. Does anybody know how to post code correctly in these forums?

By on 10/26/2008 11:42 AM ()

Here's an attempt to show code with angle brackets as well as a possible solution...

1
2
new System.Func<int,int,bool>(f)

It might be that the 'implicit conversion to delegates' changed since the publication of the book (I don't recall), but you can convert a function value 'f' to the right delegate type explicitly, as above.

By on 10/26/2008 12:09 PM ()

Thank you. This also works with underscores in place of the type parameters, so it can work with type inference it would seem.

Its unfortunate if implicit conversion to delegates has fallen out of the implementation - it makes interop with C# delegates much cleaner syntactically.

By on 10/26/2008 12:33 PM ()

I see, in the spec 14.4 has this text

<quote> Apply coercion to arguments. If a formal parameter is of delegate type D, and an actual argument <i>is syntactically a function value (fun ...),<i> then the parameter is interpreted as if it had been written new D(fun ...).</quote> (underlining added). (See also <A href="http://research.microsoft.com/fsharp/manual/lexyacc.aspx#_Toc207785624">6.5.2</A> for delegate expression creation.) In general, implicit coercions do not interact well with type inference, so perhaps this restriction keeps things simpler.

By on 10/26/2008 12:16 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper