cancel
Showing results for 
Search instead for 
Did you mean: 

Sequencing impure functions

Former Member
0 Kudos

I&#39;m writing the Graphics (or SOEGraphics) module as used in Haskell SOE, based on your Plot example. <br /> I&#39;m not sure what the best way to sequence drawing function is, in the absence of &#39;do&#39; 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&#39;t think I understand Haskell or CAL deeply enough to be sure if it is a good solution. <br /> Tom

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

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
           ;