Skip to main content
added 524 characters in body; added 32 characters in body
Source Link
Dario
  • 49.4k
  • 8
  • 99
  • 131

Could anyone give some pointers on why the unpure computations in Haskell are modeled as monads?

Well, because Haskell is pure. You need a mathematical concept to distinguish unpure computations from pure ones orbetween unpure computations and pure ones on type-level and to model programm flowsprogramm flows in it respectively.

This means you'll have to end up with some type IO a that models an unpure computation. Then you need to know ways of combiningcombining these computations of which apply in sequence (>>=) and lift a value (return) are the most obvious and basic ones.

With these twoWith these two, you've already defined a monad (without even thinking of it);)

In addition, you've already definedmonads provide very general and powerful abstractions, so many kinds of control flow can be conveniently generalized in monadic functions like sequence, liftM or special syntax, making unpureness not such a monad ;special case.

See monads in functional programming and uniqueness typing (the only alternative I know) for more information.

Could anyone give some pointers on why the unpure computations in Haskell are modeled as monads?

Well, because Haskell is pure. You need a mathematical concept to distinguish unpure computations from pure ones or to model programm flows in it respectively.

This means you'll have to end up with some type IO a that models an unpure computation. Then you need to know ways of combining these computations of which apply in sequence (>>=) and lift a value (return) are the most obvious and basic ones.

With these two, you've already defined a monad ;)

Could anyone give some pointers on why the unpure computations in Haskell are modeled as monads?

Well, because Haskell is pure. You need a mathematical concept to distinguish between unpure computations and pure ones on type-level and to model programm flows in respectively.

This means you'll have to end up with some type IO a that models an unpure computation. Then you need to know ways of combining these computations of which apply in sequence (>>=) and lift a value (return) are the most obvious and basic ones.

With these two, you've already defined a monad (without even thinking of it);)

In addition, monads provide very general and powerful abstractions, so many kinds of control flow can be conveniently generalized in monadic functions like sequence, liftM or special syntax, making unpureness not such a special case.

See monads in functional programming and uniqueness typing (the only alternative I know) for more information.

Source Link
Dario
  • 49.4k
  • 8
  • 99
  • 131

Could anyone give some pointers on why the unpure computations in Haskell are modeled as monads?

Well, because Haskell is pure. You need a mathematical concept to distinguish unpure computations from pure ones or to model programm flows in it respectively.

This means you'll have to end up with some type IO a that models an unpure computation. Then you need to know ways of combining these computations of which apply in sequence (>>=) and lift a value (return) are the most obvious and basic ones.

With these two, you've already defined a monad ;)