Is it possible to do the IO monad from Haskell in Clojure?

前端 未结 1 1956
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 00:40

I\'ve had a look at the algo.monads and fluokitten documentation. I\'ve also read through monad blog entries by Jim Duey, Konrad Hinsen and Leonardo Borges.

The closest

相关标签:
1条回答
  • 2021-02-06 00:57

    There are a few ways to answer this question.

    Yes

    • Trivially: Think of IO as a monad transformer that grants the special permission of working with side effects. Then any monad in Clojure is an IO monad, as performing side effects is not a privileged operation in Clojure.

    • Fatuously: Clojure is Turing-complete, so you could implement all of Haskell, including the IO monad in Clojure. Haskell is Turing-complete, so you could implement all of Clojure in Haskell and expose the IO monad.

    No

    • Philosophically: The essence of the IO monad, preserving purity while integrating with the type system, is incompatible with Clojure's impurity and dynamic typing. Any attempt to shoehorn in the IO monad would either be at odds with Clojure's philosophy or fail to capture the essential point of having an IO monad.

    Maybe

    • Partially: The monadic-io-streams library linked to in the question is intended for use with the algo.monads library, or its predecessor. The monadic interface is the state monad. Monadic-io-streams provides some jailed IO monadic functions to work with it. This does not prevent you from using any other functions with side effects, and without a type system integrating IO there is no systematic way to say which is which. This is not the IO monad; it just does a few things similar to the IO monad. This is interesting but of dubious utility.

    • Someday: There is interest in Typed Clojure. If side effects are added to the type system, then it may become desirable to isolate them in a structured manner for some purposes and give reason for the existence of something like an IO monad in Typed Clojure.

    0 讨论(0)
提交回复
热议问题