[Haskell-beginners] some help on do and preservingMatrix

Zsolt Ero zsolt.ero at gmail.com
Thu Nov 26 14:20:03 EST 2009


Could someone point me to some help on how does "do" work and how does
preservingMatrix?

I am trying to write a program starting from the OpenGL tutorial on
the wiki, but I never used do's.

My very basic question is that how do I generally repeat a command
many times? I understand "do" can do it, but it's not clear to me how
to use it and how it works.

So if I would like to write the following in one line, how could I write it?:
spiral 0.7
spiral 0.8
spiral 0.9
spiral 1.0

I don't understand in which cases I can use "map something
[0.7,0.8..1]" and in which cases I need do and how could I map using
do.

>From the tutorial, I could write this line, which works, but I don't
really know what does mapM_ and preservingMatrix do.

  mapM_ (\x -> preservingMatrix $ do
    scale x x (1::GLfloat)
    rotate (x*(200)) $ Vector3 0 0 (1::GLfloat)
    spiral ((sin(a/50))^2/2+0.5)
    ) $ ([0.5,0.6..1::GLfloat])

Zsolt


More information about the Beginners mailing list