Izbrane teme sodobne fizike in matematike

Monade v funkcijskem programiranju

Članek predstavi monado, eno pomembnejših struktur v programskem jeziku Haskell. Monada je za programski jezik Haskell bistvena, saj so z njeno pomočjo v Haskellu možne manipulacije z nečistimi izračuni, kot je stanje, na način, ki še vedno zagotavlja čistost ostalih izračunov. Vendar se izkaže, da uporaba monade omogoča še marsikaj drugega. Članek najprej na kratko predstavi osnovne pojme teorije kategorij, kot so kategorija, funktor, naravna transformacija in nazadnje monada. Podana je formalna definicija matematične in Haskllove monade. Na koncu se pokaže še, kako se Haskllova monada izpelje iz matematične, in dokaže njuno ekvivalenco.

Monads in functional programming

A monad is one of the most important structures in the Haskell programming language, due to its ability to manipulate impure computations, for example state, in a way which guarantees purity of other computations. As shown in the article, its use is not limited to just this purpose. The article guides the reader through some basic concepts of category theory such as category, functor, natural transformation, and monad. A formal definition of mathematical and Haskell monad is also presented. At the end it is shown how to derive Haskell monad from mathematical monad, and that they are equivalent.