Is there any way to do this in F#? Say I have a list of parameters and a function taking the same number of parameters as present in the list - how would I go about to do that?

Well, you could use a match. Not as clean, but it does either safely unpack the list or handle if it is the wrong shape.

1
2
3
let myfun a b c = a + b + c
let a = [ 1; 2; 3]
printfn "%i" (match a with [x;y;z] -> myfun x y z | _ -> failwith "Wrong shape")
By on 5/15/2009 7:53 AM ()

Thank you, that was very helpful!

By on 5/18/2009 11:37 PM ()

I don't think your suggested approach is viable (the types will not work out).

Overall I don't think there's any type-safe way to do this, so I think you'd have to invoke the method via reflection.

By on 5/14/2009 9:18 AM ()

Thank you. I have to find another way somehow.

By on 5/14/2009 11:08 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