you can change the value of a mutable variable v by using the '<-' operator - for example "v <- 3" will reassing 3 to v (of course v should be an mutable int).

By on 2/2/2009 10:00 PM ()

You could do this:

1
2
3
4
5
6
let func1 a b = a+b

let (@@) f (a,b) = f a b

let rr=func1 @@ (5,3)

although I'm not sure what you'd like to achieve here. Some kind of aspect-oriented approach perhaps?

By on 2/2/2009 8:41 PM ()

Thanks brilsmurf, however I don't think that will work for me. Basically I am dealing with user defined code that I won't have and I need some kind of operator that they can apply that will allow me to change the underlying state before the function is called. Sort of a universal indexer that they could use when writing their code. I know there are plenty of ways I could make it work but using an operator is the solution I have to have for various reasons and why I am evaluating f#. If anyone has ideas of some way to accomplish this I would be most appreciative.

Thanks

By on 2/3/2009 5:55 AM ()

Basically I am dealing with user defined code that I won't have and I need some kind of operator that they can apply that will allow me to change the underlying state before the function is called.

Maybe you should look into quotations. I'm not an expert in quotations, but I think it should allow you to do something like this.

By on 2/3/2009 6:47 AM ()

Well isn't this usually done with OO and things like abstract base classes or even SOA and services that the user code should call?

The problem I see is, that with F# you are fine as long as your users are using F# too - if not you get into trouble because the operators won't work the way you are suggesting.

By on 2/3/2009 6:22 AM ()

Well making sure the user code is in f# would not be a problem, but even f# does not seem to work in this case because it would seem that operators call there supplied functions before their code gets run, unlike a function that is supplied a function as a parameter.

I have tried this several different ways in oo with c# and there are ways to make it work but it requrires the user to create many objects and maintain them. I need a simplified way to abstract the user from all that where they can just focus on creating a function (and it can in turn call other functions with a different underlying state). I am trying to avoid going down the path of writing my own lexer/parser for this. I appreciate the input, thanks

-----

I'll look into the quotations, I am not familier with them. thanks

By on 2/3/2009 6:49 AM ()

Is there any reason why an overloaded operator is necessary? In my experience they are usually bad, or if nothing else misused. Why won't a function work?

That being said, I guess this does what you want? I'm still not 100% sure, the example seems a little strange:

> let (@@) f (a,b) = (f a) + (f b);;

> let test a = a*a;;

> test @@ (3,4);;
val it : int = 25

By on 2/3/2009 7:21 AM ()

Sorry my example wasnt the best, only been using f# a few days and was trying to keep it short. The bottom line of my question was is there a way to pass a function into the operator overload and have it called inside the operators body like a function passed into another function does. I didnt know if there was some type of special keyword or something that I could use to force it to reevaluate the function provided with its original parameters.

By on 2/3/2009 9:34 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