# Graphical Applications in Haskell with MVC and Gloss

DevFeed: [Graphical Applications in Haskell with MVC and Gloss](<https://devfeed.tech/articles/graphical-applications-in-haskell-with-mvc-and-gloss-27925.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/lectures/2022-06-27-mvc-gloss.html>)

Published: 2022-06-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [mvc](<https://devfeed.tech/topics/mvc.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Haskell](<https://devfeed.tech/topics/haskell.md>), [Graphics](<https://devfeed.tech/topics/graphics.md>), [Library](<https://devfeed.tech/topics/library.md>), [User Interfaces](<https://devfeed.tech/topics/user-interfaces.md>), [Simulation](<https://devfeed.tech/topics/simulation.md>)

Tags: [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [library](<https://devfeed.tech/tags/library.md>), [mvc](<https://devfeed.tech/tags/mvc.md>), [simulation](<https://devfeed.tech/tags/simulation.md>), [user-interfaces](<https://devfeed.tech/tags/user-interfaces.md>)

## AI overview

This article explains the model-view-controller pattern and how it maps to functional programming in Haskell. It uses the Gloss library to build a graphical application and illustrate the model, view, and event-handling components with a simple employee simulation.

## Source excerpt

Contents 1 MVC 2 Functional MVC: Gloss 2.1 Picture 2.2 Event 2.3 Gloss 1 MVC Model-view-controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. MVC says that an interactive application should consist roughly of three main parts - Model, View, and Controller. The Model is the data and state that we need to keep track of to model our application. If you're programming a Chess game, the model could consist of the state of the board (which pieces are where), the time passed since the last player played, whose turn it is, etc... The View is the definition of how our model should be displayed to the user. Intuitively, you can think of it as a function Model -> UI (and begin to see how functional MVC might be interesting). For the above example, the view would define how the chess board can be shown to the user (a 3d object, a 2d ascii board, ...), where the time passed shows up in the screen, etc. The Controller handles all events and interactions with the application and how they modify the existing model. In chess, the controller could define that when a player drags a piece in the board, the position of that piece in the board model changes to the new position, the current turn changes to the other player, and the time passed is reset to zero. And the three relate in the following manner: MVC diagram from Wikipedia 2 Functional MVC: Gloss How does the model-view-controller idea translate into functional programming? It turns out to be quite simple because the three parts match basic FP concepts. We'll focus on the library Gloss to develop a graphical application. Gloss is very easy to setup, provides abstractions for drawing graphics, and outlines the MVC compoonents clearly. We'll implement a simple simulation of the 101companies employees to illustrate the concepts. To define the model, the structure which is updated thorought the program, we simply define