do let in
Bernard James POPE
Tue, 4 Mar 2003 15:06:13 +1100 (EST)
> main =
> 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
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: