do let in

Damien R. Sullivan dasulliv@cs.indiana.edu
Mon, 3 Mar 2003 23:14:26 -0500


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-)