std::bodun::blog

PhD student at University of Texas at Austin 🤘. Doing systems for ML.

马上订阅 std::bodun::blog RSS 更新: https://www.bodunhu.com/blog/index.xml

Monads in Haskell

2020年3月1日 08:00

I’ve scratched my head for quite a while trying to understand the concept of monad in Haskell. This is a brief summary of monads. I take William Cook’s Anatomy of Programming Languages as my reference.

Definitions of Monads

A monad is defined as a computational structure that involves three parts:

  • A generic data type \(m\)
  • A return function \(return_m\) :: \(t\rightarrow mt\)
  • A bind function \(\triangleright_mt\rightarrow (t\rightarrow ms)\rightarrow ms\)

Here the symbol \(m\) gives the name of the monad as well as the shape of the computation. We can call the program that uses the monad \(m\) as an m-computation. The instantiation of the generic type \(mt\) at a particular type \(t\) represents n m-computation that produces a value...

剩余内容已隐藏

查看完整文章以阅读更多