Haskell - Does an IO monad make sense in a language like C

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

After spending a lot of time reading and thinking, I think I have finally grasped what monads are, how they work, and what they re useful for. My main goal was to figure out if monads were something I could apply to my daily work in C#.

When I started learning about monads, I got the impression that they are magical, and that they somehow make IO and other non-pure functions pure.

I understand the importance of monads for things like LINQ in .Net, and Maybe is very useful for dealing with functions that don t return valid values. And I also appreciate the need to limit statefulness in code and to isolate external dependencies, and I was hoping monads would help with those too.

But I ve finally come to the conclusion that monads for IO and handling state are a necessity for Haskell, because Haskell has no other way to do it (otherwise, you couldn t guarantee sequencing, and some calls would be optimized away.) But for more mainstream languages, monads are not a good fit for these needs, since most languages already handle and state and IO easily.

So, my question is, is it fair to say that the IO monad is really only useful in Haskell? Is there a good reason to implement an IO monad in, say, C#?

Answers

I use Haskell and F# regularly and I ve never really felt like using an IO or state monad in F#.

The main reason for me is that in Haskell, you can tell from the type of something that it doesn t use IO or state, and that s a really valuable piece of information.

In F# (and C#) there s no such general expectation on other people s code, and so you won t benefit much from adding that discipline to your own code, and you ll pay some general overhead (mainly syntactic) for sticking to it.

http://en.wikipedia.org/wiki/Type_class#Higher-kinded_polymorphism http://en.wikipedia.org/wiki/Type_class#Higher-kinded_polymorphism

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/21364837/does-an-io-monad-make-sense-in-a-language-like-c-sharp

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils