Just saw your blog about this:

[link:bugsquash.blogspot.com]

You can't completely generalize it, as it creates ambiguity in the face of overloading. For example, if there are overloads

Foo.F(int,int)
Foo.F(int,int,int)

then what type would

Foo.F 42

have?

Ad-hoc polymorphism (method overloading, as well as F# '^' types) is kinda the bane of a simple, separately-checkable type system for function values. It's ok to experiment with cool ways to get more cases to 'just work', but be wary of trying to solve the 'whole problem', as it is... non-trivial.

By on 1/22/2009 10:26 AM ()

Yup, I realized that. I concluded at the end of the post that my approach doesn't work :-)
That's why I said that it would be nice to have this somehow integrated into the language, although I do realize that this would be very hard to achieve.
I won't try to solve the "whole problem" (I'm just an F# and overall FP newbie), but as a workaround, I'm thinking about creating curried wrappers with Mono.Cecil or with generated code.

By on 1/22/2009 2:14 PM ()

As far as I know there's no standard way of doing this. I'd be interested to see your generic curry, since I would of thought it would be difficult because of F#'s static typing. Could you show us what you've written?

Cheers,

Rob

By on 1/12/2009 4:13 AM ()

Here are my experiments so far. I used method overloading to hide the different curry methods needed because of the static typing. It's not pretty, but it seems to work for non-overloaded methods. When trying to apply FP.curry to an overloaded method, it doesn't know which overload to pick so it won't compile.

Also, I found a weird error when trying to define the overload for 6 parameters:

// does not compile:// Type mismatch. Expecting a 'a but given a 'b * 'c * 'd * 'e * 'f * 'a -> 'g. The resulting type would be infinite when unifying ''a' and ''b * 'c * 'd * 'e * 'f * 'a -> 'g'.// [<OverloadID("curry5")>]// static member inline curry (f:_*_*_*_*_*_ -> _) = // fun a b c d e f -> f (a,b,c,d,e,f)
Any feedback is welcome.

Cheers,
Mauricio

By on 1/12/2009 5:28 AM ()

Mauricio,

Your error is probably due to the fact that your last argument is called 'f', the same as the function you're currying.

Kurt

By on 1/12/2009 7:28 AM ()

Heh, didn't see that one. Thanks, Kurt!

By on 1/12/2009 7:44 AM ()
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