4 ms·
the simple use of "Either" does not instantly qualify something as "monadic" you know what else is monadic? NULL pointers. oh wait, you know what else is monad
by rian 15y ago
the simple use of "Either" does not instantly qualify something as "monadic"
you know what else is monadic? NULL pointers. oh wait, you know what else is monadic? unix pipes. you know what else is monadic? CPP. really old shit.
just because the word monad isn't everyday english doesn't make it a cool or even an interesting concept. it's just an awkward abstraction for something everyone already intuitively understands. monads were invented for the sole purpose of giving haskell a programmable model for IO, that's it. it's just a concept that's only useful for haskell programming, everything else already has an intuitive programming model for IO.
it's like building up integers to be this crazy complicated concept and then saying Exceptions are integers. awesome, good job, you've just found an equivalence, here's a pat on the back (psst http://en.wikipedia.org/wiki/Church_encoding http://en.wikipedia.org/wiki/Church_encoding). i guess i should expect these kinds of vacuous observations given all the BufferedManagerFactorySingleton crap code java slaves write.
you know what else is monadic? state machines. you know what else is monadic? imperative programming. wait wait wait! you know what else is monadic? JAVA ITSELF head explodes
- gmartres 15y agoSo, what's the intuitive equivalent to monadic parsers combinators? (see http://www.cs.nott.ac.uk/~gmh/monparsing.ps http://www.cs.nott.ac.uk/~gmh/monparsing.ps which incidentally is a great introduction to monads). Similarly, now that I have some understanding of monads, I find myself wishing I could use them(particularly the State monad) in other languages to reduce the boilerplate.
- rian 15y agosigh, http://boost-spirit.com/home/ http://boost-spirit.com/home/
- Peaker 15y agoThis is an example from this parsing framework: text = lexeme[+(char_ - '<') [_val += _1]]; node = (xml | text) [_val = _1]; start_tag = '<' >> !lit('/') >> lexeme[+(char_ - '>') [_val += _1]] >> '>' ; end_tag = "</" >> string(_r1) >> '>' ; xml = start_tag [at_c<0>(_val) = _1] >> *node [push_back(at_c<1>(_val), _1)] >> end_tag(at_c<0>(_val)) ; The (>>) operator here is defined in the same as the Applicative/Monad bind: (>>). For the effect of full monadic bind (>>=), the explicit assignment into "val" is used. Here is the same example encoded using Monadic Parsec: text = many (notChar '<') node = xml <|> text start_tag = do char '<' notChar '/' val <- many (notChar '>') char '>' return val end_tag name = do string "</" string name char ">" xml = do name <- start_tag val <- node end_tag name return (name, val) Now, one interesting difference between Parsec and the spirit framework, is that Parsec instantiated the Monad class to allow composition of Parsers, whereas spirit defines its own ad-hoc combinators. This means that with parsec, I can use all of the existing monadic functions. For example, I can use the "replicateM" function, which replicates a monadic action N times to say I want 3 XML elements in sequence: replicateM 3 xml Or I can use one of the hundreds of others of available combinators. Of course boost spirit can also encode these combinators on top of their own ad-hoc operators, but they would be: * Duplicate code with every other monadic framework * Another vocabulary to learn in order to compose parsers * Cannot re-use any third party code that works with every monad in existence
- Peaker 15y agoI'm sorry but almost every sentence in your comment is wrong: > the simple use of "Either" does not instantly qualify something as "monadic" The composition of calls to functions that return Either as to implement exceptions is exactly Monadic. > you know what else is monadic? NULL pointers. oh wait, you know what else is monadic? unix pipes. you know what else is monadic? CPP. really old shit. Only if very loosely interpreted. NULL pointers are not monadic. Maybe types are monadic (and also considered an "Exception monad"). Unix pipes are not monadic in a meaningful way (they don't support the monadic operations), but approximations/implementations of them can be. In what sense is the C preprocessor monadic? > just because the word monad isn't everyday english doesn't make it a cool or even an interesting concept. it's just an awkward abstraction for something everyone already intuitively understands. Cool and interesting are subjective concepts. I find them pretty cool, in the sense of capturing one of the most general patterns in code I've ever seen captured. In what sense are monads an "awkward" abstraction? > monads were invented for the sole purpose of giving haskell a programmable model for IO, that's it. it's just a concept that's only useful for haskell programming, everything else already has an intuitive programming model for IO. That's completely false. Monads don't have anything to do with IO, it's just a particular instance of them. I can make a list of Bananas, does a list have anything to do with bananas? Monads are immensely useful for many things. When using Haskell, I can use a very large set of combinators that work with any monad, to compose Parsers, functions, Maybe values, and various other types. This means I can re-use a lot more code and vocabulary. When I learn an API, I don't have to read the documentation and types of 30 specific combinators. Instead, the library just says: "This type has a monad instance" -- and I can use my existing knowledge to work with it. > it's like building up integers to be this crazy complicated concept and then saying Exceptions are integers. awesome, good job, you've just found an equivalence, here's a pat on the back No -- the semantics of statement composition in the face of exceptions is the only valid instance of Monad for Either values that encode them. It's not like you have to go very far to find this equivalence. Integers are not usefully equivalent to exceptions. > i guess i should expect these kinds of vacuous observations given all the BufferedManagerFactorySingleton crap code java slaves write. This observation is actually one of the first uses of monads in the Haskell crowd, not in the Java crowd. > you know what else is monadic? state machines. you know what else is monadic? imperative programming. wait wait wait! you know what else is monadic? JAVA ITSELF head explodes I think you've completely missed the point of Monads. Take a look at: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html http://haskell.org/ghc/docs/latest/html/libraries/base/Contr... I can use any of the combinators in there with any monad instance. The fact I can use them with Either values makes Either value composition behave exactly like exceptions. This is not a "neat observation" -- it is something people routinely use, plentifully.
- thesz 15y agoUnix pipes are Applicative: http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base/Control-Applicative.html http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base/C... Applicative and Unix pipes cannot change their computation topology. >monads were invented for the sole purpose of giving haskell a programmable model for IO, that's it. Monads were known long before Haskell. They just used in Haskell for IO and for much more things.
- Tinned_Tuna 15y agoIt's a common theme in mathematics to show an equivalence between two structures. We don't do it because it's fun, it's because if there exists an equivalence or some other relationship, we can use the existing body of work in one field in another. For example, group and ring theory often starts with the concept of symmetries, but it can then be shown, through an equivalence (or in mathematical terms, an isomorphism) that these have a relationship to polynomials. From that, we then easily show that there is no general formula for polynomials of degree greater than 5. Two vastly different fields, actually sharing something, and having a very useful result. Similarly for finite state machines and monoids. If you can express something as something else, you have the opportunity to shed light on it's structure and hence learn something new about it. Yes lots of things share that structure, it just so happens that monads are quite a general structure, that doesn't mean that no interesting results are attached to them.