Skip to Content
author's profile photo Former Member
Former Member

Sequencing impure functions

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 04:53 AM

    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
    Â Â Â Â Â Â Â Â Â Â Â ;

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.