Previous Thread
In the last thread we explored Partiality and Exceptions:
Index to other threads on functional programming:
- History of Functional Programming / Category Theory
- Category Theory for programmers
- Functional design approach to a problem
- Recursion, Composition, Pipe Forward, Higher Order Function, Side Effects
- Covariance / Contravariance, Reducers / Transducers
- Predictable State Engine
- Functions
- Exception Handling
- Lazy Transformations / Yoneda and Coyoneda
- Monadic Computations / Nullable
- Algebraic Data Types / Tagged Union Types
- Monadic Composition
- Traversable Functors
- Partiality and Exceptions related to Kleisli Categories.
Tetris

This thread will be a code heavy thread targeted at an intermediate level.
It will focus on building a Tetris game using a pure functional approach. During the course of the build we'll build a pure functional logic core mixed initially with an imperatively all in one coded MVC (Model / View / Controller) to show that functional code can easily exist side by side with both imperative and OOP style of design.
In the second part of this thread we'll push the boundaries of the functional design by converting all the imperative code in our MVC (Massive View Controller) in order to create a clear separation between the Model, the View and the Controller, at the same time splitting off as much of the code as possible to a multi-platform shared codebase; with the final intention of creating a project that is capable of running on Windows, Linux, macOS and Android... and that can fairly easily be adapted for iOS, Xbox, Playstation, etc.
To achieve the clear separation with MVC; we'll be building a custom Actor Model implementation of the Redux state engine that will process all state (model) changes on a background thread.
What will be needed for anyone that would like to follow along:
- Language : F# (latest version 4.7)
- .Net framework: 3.0
- Game framework : Monogame.Net
- IDE: Visual Studio for Windows or Visual Studio for Mac, or alternatively Visual Studio Code on Linux
F# for this build; the code should quite easily translate to any of the mainstream languages. F# has built in support for the Actor Model (called MailboxProcessor); this in not available on C# or VB.Net, however as a substitute you can use Akka.Net for C# and Vb.Net and similarly Akka for Java, Scala and Kotlin.Alternatively you can use any existing Redux or Flux implementation as a substitute. In non .Net languages you'll have to also pick a game framework, or use libGDX or OpenTK or .... and build your own game loop. As for Javascript; I'd suggest just using Redux or Flux with the canvas for the render.
Any questions you may have should either be posted into this thread or sent as a PM.
Timeline
This is probably going to be a Christmas into New Year build, but as I've already written quite a bit of the code already as part of a FP teaching exercise. I should be able to start dropping code in a day or two; the explanation of the design approach and implementation is the part that typically takes up more time. Either way we should wrap this up in the new year or before; Finally I'll end off by pushing a final working project up to github.
Last edited:










