Main function variables made global.

?Hello, My problem is as follows (not actual code), I declare a function outside of the main function func w = w * var I get the value of 'var' from a text file in the main function (as the user types the name of the file into terminal) I need a way for 'func' to see what 'var' is without having to change it's type (ie make it into a function which take a 'w' and a 'var'. The reason I can't change the type is that I then pass the function to a PSO module which has strict declarations of a function and I would rather not change the PSO module. I also can't put 'func' into main because 'w' isn't specified. The PSO will find the best w so I don't get it a value. I have thought about making a dummy function which has an input of 'w' and 'var' and an output of a function of just 'w'. Something like: func w = func' w var. I got the function for PSO to optimise and the function to get the data I want from a text file working great, they both do what they're supposed to do. I just need the function of PSO to see the data I get from the file. If you need any more information (sorry if I've been too vague) please let me know. Thank you for your time.?

On Thu, Mar 27, 2014 at 10:58:45AM +0000, Chapman, Anthony Sergio wrote:
func w = w * var
I get the value of 'var' from a text file in the main function (as the user types the name of the file into terminal)
I need a way for 'func' to see what 'var' is without having to change it's type (ie make it into a function which take a 'w' and a 'var'.
The reason I can't change the type is that I then pass the function to a PSO module which has strict declarations of a function and I would rather not change the PSO module.
It's not quite clear to me what you're asking, but won't something like this do? do var <- readVar let func w = w * var let result = psoFunction func Tom

Anthony, maybe simply add var as a parameter and partially apply func in main? That'll give you the right type. Michal Original Message From: Tom Ellis Sent: Thursday, March 27, 2014 7:06 AM To: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Main function variables made global. On Thu, Mar 27, 2014 at 10:58:45AM +0000, Chapman, Anthony Sergio wrote:
func w = w * var
I get the value of 'var' from a text file in the main function (as the user types the name of the file into terminal)
I need a way for 'func' to see what 'var' is without having to change it's type (ie make it into a function which take a 'w' and a 'var'.
The reason I can't change the type is that I then pass the function to a PSO module which has strict declarations of a function and I would rather not change the PSO module.
It's not quite clear to me what you're asking, but won't something like this do? do var <- readVar let func w = w * var let result = psoFunction func Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Mar 27, 2014 at 08:07:59PM +0100, Marc Ziegert wrote:
It seems to me you are asking for this unsafePerformIO hack [...]
I don't think that's the case at all. It seems to be a simple case of lifting a partial application into the IO monad. There's nothing strange about it. Tom
participants (4)
-
Chapman, Anthony Sergio
-
mantkiew@gsd.uwaterloo.ca
-
Marc Ziegert
-
Tom Ellis