4 ms·
I've tried this a lot, and I will say no, it's not realistically possible if you're being a purist. The simple counterexample, take setpixel, which takes an im
by joeld42 3y ago
I've tried this a lot, and I will say no, it's not realistically possible if you're being a purist.
The simple counterexample, take setpixel, which takes an image buffer, and returns an image buffer with one pixel changed. Now imagine having a large bitmap and using setpixel to draw a sprite to it. For every non-transparent pixel in the sprite you need a whole copy of the whole buffer. Obvs there are lots of improvements and cleverness but compared to the speed and simplicity of an imperative code just modifying an image buffer in-place it's vastly slower, more complicated or both.
However you can manage to write "most" of your game in a functional way and if you're careful about it, and use tricks like copy-on-write to make some things act functional, you can do it. Writing your game in a functional mindset, and keeping data immutable when you can has a lot of benefits.
- kelseyfrog 3y agoWe might be getting into semantics, but if you're willing to agree that IO monad maintains functionality, then there's no reason a Bitmap monad couldn't do the same for pixel writing. In principle and practice, all effects can be pushed to the outside of all applications.
- pjmlp 3y agoNot every FP language is Haskell.
- tylerhou 3y agoWhy doesn’t a state monad work?