[HOpenGL] Newbie: Difference between $= and <- operators?
Sven Panne
Sven.Panne at aedion.de
Sun Apr 26 09:40:52 EDT 2009
Am Freitag, 20. März 2009 17:00:57 schrieb Jeff Heard:
> the $= only works for OpenGL state variables, whereas <- won't work
> for them. [...]
This is partly correct: $= and friends work for e.g. IORefs, too. As Jeff
already pointed out, the "do" notation is only handy way to combine monadic
actions and bind values to names (this is what <- effectively does). OTOH,
have a look at the signature of $= below:
class HasSetter s where
($=) :: s a -> a -> IO ()
"foo $= bar" does not bind foo to bar, it executes some action, using foo and
bar. In the case when foo is an IORef, it puts the value named by bar into
foo. In the case when foo is some kind of OpenGL state variable, it changes
the corresponding part of the OpenGL state machine (calling the driver,
setting up HW, etc.).
In other words (slightly simplified): You can think of $= as an actual
"imperative" assignment, while <- is a binding construct, giving a value a
name.
Cheers,
S.
More information about the HOpenGL
mailing list