10 ms·
> They can express any effect but they can't express restricted subsets of effects. This is not true. E.g., see my blog post, http://blog.paralleluniverse.co/2
by pron 9y ago
> They can express any effect but they can't express restricted subsets of effects.
This is not true. E.g., see my blog post, http://blog.paralleluniverse.co/2015/08/07/scoped-continuations/ http://blog.paralleluniverse.co/2015/08/07/scoped-continuati..., with references to work by Oleg Kiselyov on typed continuations. Having said that, restricting effects is one of those solutions in search of a problem, at least at the moment. It is very questionable whether this has any substantial benefit, and the Java philosophy calls for adopting only features that have proven their (significant!) worth. On top of that, Scala can't restrict effects, either.
> You can write Option-oriented code without it being a second-class citizen
Which, BTW, Java discourages. Option is mainly recommended for use in functional composition in streams. For general null-safety, Java has pluggable nullability types (and many other useful pluggable types), similar to Kotlin's built-in nullability types. See https://checkerframework.org/ https://checkerframework.org/. Unfortunately, it's not yet seeing much adoption, largely due to the relatively low-key marketing of Checker and the fact that it's been not too user-friendly until quite recently. However, this is the recommended solution, e.g. in the Java tutorial: https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html https://docs.oracle.com/javase/tutorial/java/annotations/typ....
> putting together any of the features it does support should work the right way; it's not at all clear that this is the case for kotlin
Right, and certainly Kotlin has not yet proven itself (and neither has Scala), but in my opinion, this is quite clearly not the case for Scala. E.g., monads and the imperative control structures in Scala simply do not compose. You must commit to one or the other.
> And certainly when you end up copy-pasting code because you're using the same logic but the language doesn't let you express how it's the same, that's a problem with your language.
Not when that's required for non-idiomatic code. And, BTW, I believe that the pure functional paradigm in general suffers very strongly from this in a way that's very essential to the core of the paradigm (because typed monads introduce a dependence of code structure on a nominal type, i.e., the same computation can be expressed using different monads -- or no monads at all -- in a way that is non-composable or requires awful monad transformers).
- lmm 9y ago> see my blog post, http://blog.paralleluniverse.co/2015/08/07/scoped-continuati... http://blog.paralleluniverse.co/2015/08/07/scoped-continuati..., with references to work by Oleg Kiselyov on typed continuations. So a theoretical type system extension that Kotlin doesn't actually have could solve this, and looks ok in simple examples. That's not terribly reassuring and not much help to anyone writing Kotlin today; anyone wanting to do the equivalent of something basic like traverse or, I don't know, cataM will still have to either copy/paste their code or give up type safety. > On top of that, Scala can't restrict effects, either. In theory no. In practice I use traverse all the time without worrying about whether the function I called was secretly throwing an exception or modifying a global variable, and it hasn't caused a bug yet; the community and culture can mostly work around the lack of hard restrictions at the language level. > Which, BTW, Java discourages. Option is mainly recommended for use in functional composition in streams. I know that's the official line, but it still works in a first-class way in practice (which to my mind is the sign of good language design; you can't expect language designers to anticipate all your needs, so it's important that things continue to work even if used in unexpected ways). > I believe that the pure functional paradigm in general suffers very strongly from this in a way that's very essential to the core of the paradigm (because typed monads introduce a dependence of code structure on a nominal type, i.e., the same computation can be expressed using different monads -- or no monads at all -- in a way that is non-composable or requires aweful monad transformers). There are now ways to avoid having to copy-paste in that situation e.g. MTL-style code ("final tagless") or free coproduct style.
- pron 9y ago> So a theoretical type system extension that Kotlin doesn't actually have could solve this There is nothing to solve unless a problem is identified, which, to date, none has (except within the context of pure FP). > and looks ok in simple examples Kiselyov treats general cases, and AFICT, his work on algebraic effect systems uses exactly the same approach. > it hasn't caused a bug yet; the community and culture can mostly work around the lack of hard restrictions at the language level. Well, you were talking about language support. The fact is that monadic style and the imperative control structures provided by Scala simply do not mix well, so why does Scala have both? Anyway, Kotlin doesn't want to buy into that programming paradigm. That's just your aesthetic choice. > There are now ways to avoid having to copy-paste in that situation e.g. MTL-style code ("final tagless") or free coproduct style. While I'm only a little familiar with free algebras from a theoretical POV, and all I know about "final tagless" is that it aims to achieve something similar to object algebras in OOP code, I believe those "free interpreter" styles are both expensive performance-wise (they require to represent code as a runtime data structure), and just expose an underlying fundamental problem in the language (there is also the deep problem -- which is mostly theoretical, but I'm also interested in theory, and find the FP theory to be both weak and complex compared to newer alternatives -- that monadic code can be computationally identical to non-monadic code, e.g. simple recursion vs. running in a state monad, yet the two have completely different denotations and inhabit incomparable types; if monadic code is the more general form, there are theories that do something similar, but in a way that's more uniform, simpler, and much more amenable to formal analysis; but I digress). In general, one could say that any language with extensive DSL capabilities can fix any problem, but there are very good reasons to avoid powerful DSL support. This is one of the things I find most interesting in Kotlin. It offers some DSL support (inline functions, builders), which seems powerful, yet still doesn't take embedding too far. Is this a sweet spot? Does it do harm by adding features that don't solve hard problems yet introduce complexity? I don't know, but it will be interesting to see.
- lmm 9y ago> The fact is that monadic style and the imperative control structures provided by Scala simply do not mix well, so why does Scala have both? Which control structures? "for" extends very nicely to monadic style, as do if/else expressions. I guess do/while and throw/catch don't, but the language syntax is flexible enough that it doesn't really matter, because these builtin control structures are only barely more privileged than user-defined functions. (To answer your question, probably Java compatibility). I mean, don't get me wrong, I'd like to see them removed from the language, but it's not like anything would go wrong if you used while in a monadic context. throw I will grant you doesn't mix well with the rest of the language; the JVM means the possibility of exceptions is something we have to live with, but from a pure language design point of view it would be better to be without it, sure. > That's just your aesthetic choice. Aesthetics have nothing to do with it; it's my experience of what does and doesn't produce reliable, maintainable code. > "free interpreter" styles are both expensive performance-wise Free interpreter style can be expensive performance-wise; final tagless doesn't have that problem (indeed I see a lot of similarity between that style and various effect/ambient handler styles, for better and for worse). > that monadic code can be computationally identical to non-monadic code, e.g. simple recursion vs. running in a state monad, yet the two have completely different denotations and inhabit incomparable types What do state and recursion have to do with each other? Are you assuming some unmodelled language-level feature like mutable variables?