5 ms·
If people are going to use denotational semantics to emulate a state-capabale environment, it's better if the method for doing so is standardized, well-specifie
by jrockway 17y ago
If people are going to use denotational semantics to emulate a state-capabale environment, it's better if the method for doing so is standardized, well-specified, and optimized.
I am not following you here. State is nothing special, except that it is something made special by most popular programming languages. (Where it causes lots of fun problems.)
I am also not sure that "Monads" are optimized any more than any other function application. Monadic state-passing is syntax sugar more than anything else. (With other languages, state is "something else"; lexical environments, dynamic environments, and so on.)
- whatajoke 17y agoState is nothing special, except that it is something made special by most popular programming languages. (Where it causes lots of fun problems.) With very elementary design decisions, mutable state is very much manageable in the most popular languages. Hiding state maintenance through a monad solves very little, while throwing performance out of the window. Yeah, you can get performance out of a lazy functional language, but the hoops you have to jump through are not worth it. Ocaml is eager functional, and IMHO is a very nice compromise between expressibility and purity. Now if only its type system was as capable as haskell, and only if it had multi processor support :(
- loup-vaillant 17y ago"Now if only its type system was as capable as haskell" One of the reasons is precisely the "impurity" of the language. I am referring to the value restriction, which inserts `'_a` (which means "because of possible side effects, this value won't have a polymorphic type, sorry") sometimes when you do partial applications (even ones without any side effect). It bit me once when I tried to do FRP (Yampa-style) in Ocaml. I couldn't define some of the operators (time) in a modular way (in terms of integral) without losing polymorphism. Another reason has to do with the fact that Ocaml is strict. I tried to define a mini "batteries" module with purely functional lazy lists instead of destructive streams (the enumeration). There is simply no way to define map or filter in terms of fold without losing laziness, or seriously polluting the type of fold, map, and filter. This can still be regarded as a type system issue : if strict and lazy types were compatible, as they are in Haskell, it wouldn't have been such a problem.
- jmillikin 17y agoMonads handle much more than state -- they're an elegant alternative to exception handling, IO, and anything sequential. There's no performance penalty involved in using a monad, and very little penalty for using lazy evaluation. I've written Haskell code which is on even ground performance-wise with C, and no hoops were involved. Monads are also not a feature of Haskell -- they can be used in any language which supports closures. I've used them in Python to great effect, though the lack of syntax support is annoying.
- lmkg 17y agoIt's not about state, it's about denotational semantics. A pure functional language can use denotational semantics to embed non-pure languages/programs/concepts, because the denotational semantics of non-pure concepts are still pure. State is the most common example of a non-pure concept that many programmers miss in Haskell, but it's not the only one. So it's not a question of state being useful or awesome or even a good idea, but rather a question of how Monads are how Haskell escapes its own constraints to express 'foreign' ideas. My point was that, in practice, if pure functional langues ruled the world and did not include built-in Monads, many applications would re-invent them anyways because of their expressivity, in much the same way that C applications are said to re-invent LISP.