Quote:Original post by hymerman
Niktheblak: I'm investigating it now. I figured functional programming may be able to help me, I just don't know if my mind is ready for it yet! How on earth do I draw to the screen in a functional language...?
The following code draws a star on the screen in Haskell, using OpenGL. Taken from here.
ex2 :: IO ()ex2 = do color (Color3 0.0 1.0 0.0 :: Color3 GLfloat) beginEnd LineLoop $ mapM_ vertex [ Vertex3 0.20 0.10 0.0, Vertex3 0.50 0.90 0.0, Vertex3 0.80 0.10 0.0, Vertex3 0.10 0.60 0.0, Vertex3 0.90 0.60 (0.0 :: GLfloat)]
In Haskell you basically have a datatype, IO, which represents an "action" - writing to a file, or drawing on the screen. This datatype also happens to be a "monad". A monad is basically a datatype which implements the Monad interface (type class) and obeys a few rules - there are many more useful monads that have nothing to do with IO. The 'do' syntax seen above looks imperative, but is transformed into code using this functional interface.
This setup allows the language to keep referential transparency, while still interacting with the outside world. The code responsible for building actions is kept as localised as possible, so you have a few top-level functions responsible for effects calling out into effect-free code which does most of the work.
I highly recommend picking up Haskell. As a bonus, you'll see how static typing done correctly really is a feature.