3 ms·
I could be misunderstanding here, but isnt this what monads are for?
by binarymax 14y ago
I could be misunderstanding here, but isnt this what monads are for?
- w_t_payne 14y agoI thought that monads were something to do with I/O? (I never really grokked Haskell, so please forgive my ignorance).
- binarymax 14y agoIm not a Haskell guy either, but monads are a concept not restricted to Haskell. A trivial example is if you know jQuery - $(".myclass").addClass("myclass2") ...the selector returns zero or more objects. You dont need to iterate over each and manually add myclass2.
- w_t_payne 14y agoOh. I did not know that. I will have to investigate further. Thank you.
- dbaupp 14y agoNote that jQuery isn't necessarily a monad in the strictest sense (i.e. it's unclear whether it satisfies the laws), but it certainly has many attributes that are similar, and so is a good example nonetheless. Reference: http://stackoverflow.com/questions/10496932/is-jquery-a-monad http://stackoverflow.com/questions/10496932/is-jquery-a-mona...
- ajanuary 14y agoMonads are a general concept that happen to be a handy way to wrap up IO and protect Haskell from the ugliness of its impure nature. At its core, monads have nothing to do with IO and are used in a lot of non-IO situations. I'd recommend Google for "Maybe monad in {insert favorite language here}" to at least grok the idea that monads are a more general concept.
- w_t_payne 14y agoOh. Is that what they are? Never knew that. Well, you learn something new every day. :-) (Thank you very much).
- dbaupp 14y agoIO is just one example of a monad. (It might be called the "canonical" example, since monads provide a very neat functional solution to the highly non-function problem of interacting with the real world.) Other examples include lists and functions. (Anything which satisfies the monad laws can be called a monad, there isn't any restriction or definition other than that.)
- w_t_payne 14y agoHaving done a little bit of reading, I would have to agree. Yes, this is exactly what monads are for.