
main = do args <- System.getArgs let (m, b) = (read (args!!0), read (args!!1)) let lim :: Int lim = read (args!!2) printstate = args!!3 time1 <- getClockTime let n = 2^b let afact = array (0,n) ((0,1):[(i,i*afact!(i-1)) | i<-[1..n]]) in let (glo, ghi) = gamma_tup lim m b time2 <- getClockTime gives the Hugs error ERROR "gamma3_7.hs":141 - Syntax error in expression (unexpected `;', possibly due to bad layout) I tried indenting the last two lines, or just the penulatimate line, but no joy. I've modified my functions to use afact instead of fact, but I'm hoping to have it exist as a global for them, rather than modifying all the function signatures to pass afact down the chain. Help, please? -xx- Damien X-)

in 'do' notation, 'let' doesn't take an in. so you want to get rid of the 'in' on the third to last line.
main = do args <- System.getArgs let (m, b) = (read (args!!0), read (args!!1)) let lim :: Int lim = read (args!!2) printstate = args!!3 time1 <- getClockTime let n = 2^b let afact = array (0,n) ((0,1):[(i,i*afact!(i-1)) | i<-[1..n]]) in let (glo, ghi) = gamma_tup lim m b time2 <- getClockTime
gives the Hugs error ERROR "gamma3_7.hs":141 - Syntax error in expression (unexpected `;', possibly due to bad layout)
I tried indenting the last two lines, or just the penulatimate line, but no joy. I've modified my functions to use afact instead of fact, but I'm hoping to have it exist as a global for them, rather than modifying all the function signatures to pass afact down the chain.
Help, please?
-xx- Damien X-) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Damien writes:
main = do args <- System.getArgs let (m, b) = (read (args!!0), read (args!!1)) let lim :: Int lim = read (args!!2) printstate = args!!3 time1 <- getClockTime let n = 2^b let afact = array (0,n) ((0,1):[(i,i*afact!(i-1)) | i<-[1..n]]) in let (glo, ghi) = gamma_tup lim m b time2 <- getClockTime
gives the Hugs error ERROR "gamma3_7.hs":141 - Syntax error in expression (unexpected `;', possibly due to bad layout)
I tried indenting the last two lines, or just the penulatimate line, but no joy. I've modified my functions to use afact instead of fact, but I'm hoping to have it exist as a global for them, rather than modifying all the function signatures to pass afact down the chain.
Help, please?
Did you supply all of the code for main, or did you chop it off at some point? I'm not exactly sure what you want to do, but I'm guessing that you want the variable afact to be in scope on the right-hand-side of some other functions in your program (gamma_tup, for example). For whatever reason you do not want to pass it explicitly as an argument? Have a read your question properly? If not I'm sorry. So perhaps you want to simulate a global variable. John Hughes has written a nice paper for the Journal of FP that discusses some design considerations for global variables in Haskell (+ extensions). Perhaps you could have a quick read of it. You might find a suitable solution in there. The paper is called: Global Variables in Haskell. You can get a draft from his web-site, http://www.math.chalmers.se/~rjmh/ Also while you are at it, you might want to read the rules for do-notation syntax, this might help with your syntax problems. Section 3.14 of the (revised) Haskell 98 Report: http://research.microsoft.com/Users/simonpj/haskell98-revised/haskell98-repo... Cheers, Bernie.

On Tue, Mar 04, 2003 at 03:06:13PM +1100, Bernard James POPE wrote:
Damien writes:
main = do args <- System.getArgs let (m, b) = (read (args!!0), read (args!!1)) let lim :: Int lim = read (args!!2) printstate = args!!3 time1 <- getClockTime * let n = 2^b * let afact = array (0,n) ((0,1):[(i,i*afact!(i-1)) | i<-[1..n]]) in let (glo, ghi) = gamma_tup lim m b time2 <- getClockTime
Did you supply all of the code for main, or did you chop it off at some point?
I did chop it off, but the only new lines were the ones I've marked with a * in this e-mail, and the rest works.
I'm not exactly sure what you want to do, but I'm guessing that you want the variable afact to be in scope on the right-hand-side of some other functions in your program (gamma_tup, for example).
Exactly.
For whatever reason you do not want to pass it explicitly as an argument?
For the reason that I'm lazy and don't want to have to modify all my functions which use afact, or call functions which use afact, and don't see why I should have to -- they were able to call the 'fact' function as a global, and can refer to a global 'afact' if I define it outside of main with a fixed value. I don't see why having a global dependent on outside input should be so much harder.
So perhaps you want to simulate a global variable.
Yeah. And I've tried various permutations let afact = ... in let (glo, ... let afact = ... in (glo, ... let afact = ... in (glo, ... let afact = ... let (glo... etc. -xx- Damien X-)

Hi,
For the reason that I'm lazy and don't want to have to modify all my functions which use afact, or call functions which use afact, and don't see why I should have to -- they were able to call the 'fact' function as a global, and can refer to a global 'afact' if I define it outside of main with a fixed value. I don't see why having a global dependent on outside input should be so much harder.
Of course afact depends on the value of n, which is only known in main. So you need a way of passing n to afact, and you get the same problem as before.
So perhaps you want to simulate a global variable.
Yeah. And I've tried various permutations
let afact = ... in let (glo, ...
let afact = ... in (glo, ...
let afact = ... in (glo, ...
let afact = ... let (glo...
None of these will work because of the scoping rules in Haskell (which are static, perhaps you are used to languages with dynamic scope?). If you follow the desugaring rules for do notation, it might be clearer how the scoping rules work. I posted a reference in my previous mail. So if you want a global variable - read the paper by Hughes that I mentioned previously. It is short, easy to understand, and covers the typical ways Haskell programmers might try to do it (dirty and clean). It might even clarify the scoping issues involved. If you can't be bothered to read the paper, then I'm afraid you'll have to thread the value of afact through your code. Cheers, Bernie.

On Tue, Mar 04, 2003 at 03:29:48PM +1100, Bernard James POPE wrote:
So if you want a global variable - read the paper by Hughes that I mentioned previously. It is short, easy to understand, and covers the typical ways Haskell programmers might try to do it (dirty and clean). It might even
I've read it and looked at the implicit parameters paper ghc points to. Implicit parameters seem like what I'd want, but I can't get that to compile either. But it's getting late and I should probably go back tomorrow. (Turned all uses of afact into ?fact, and tried let ... gamma_tup ... with afact = array ... And compiled with -fglasgow-exts) -xx- Damien X-)

On Tue, Mar 04, 2003 at 03:29:48PM +1100, Bernard James POPE wrote:
So if you want a global variable - read the paper by Hughes that I mentioned previously. It is short, easy to understand, and covers the typical ways Haskell programmers might try to do it (dirty and clean). It might even
I've read it and looked at the implicit parameters paper ghc points to. Implicit parameters seem like what I'd want, but I can't get that to compile either. But it's getting late and I should probably go back tomorrow. (Turned all uses of afact into ?fact, and tried let ... gamma_tup ... with afact = array ... And compiled with -fglasgow-exts)
I think the use of the "with" keyword is deprecated. Instead of, foo with ?u=bar you should now use, let ?u=bar in foo That might be it. J.A.
participants (4)
-
Bernard James POPE
-
Damien R. Sullivan
-
Hal Daume III
-
Jorge Adriano