on 10-22-2006 4:20 PM
I'm writing the Graphics (or SOEGraphics) module as used in Haskell SOE, based on your Plot example. <br /> I'm not sure what the best way to sequence drawing function is, in the absence of 'do' and the IO Monad. <br /> For example, where SOE has sierpinskiTri w x y size = if size <= minSize then fillTri w x y size else let size2 = size `div` 2 in do sierpinskiTri w x y size2 sierpinskiTri w x (y - size2) size2 sierpinskiTri w (x + size2) y size2 I have: sierpinskiTri w x y size = if size <= minSize then fillTri w x y size else let size2 = size / 2; in seq (sierpinskiTri w x y size2) (seq (sierpinskiTri w x (y - size2) size2) (sierpinskiTri w (x + size2) y size2) ); My solution works, but I don't think I understand Haskell or CAL deeply enough to be sure if it is a good solution. <br /> Tom
Using seq to explicitly order (i.e. sequence) stateful computations is a good idea. When using seq this way, we tend to use it in operator form (using the backquote syntax) to improve readability. For example:Â
sierpinskiTri w x y size =
   if size <= minSize then
       fillTri w x y size
   else
       let
           size2 = size / 2;
       in
           sierpinskiTri w x y size2
           `seq`          Â
           sierpinskiTri w x (y - size2) size2
           `seq`
           sierpinskiTri w (x + size2) y size2
           ;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.