3 ms·
Can you explain why you think so?
by nathas 12y ago
Can you explain why you think so?
- lmm 12y agoMost of the selling points on scala-lang.org still apply over C# - type inference, pattern matching, case classes (C# makes these less bad than Java, but the field/property distinction can still bite you), an inheritance model that supports the good parts of multiple inheritance without the problems, covariance/contravariance, for/yield syntax that's generic and user-controlled, higher-kinded types. It takes a while for your code to get big enough for the last part to matter, but it's huge when it does - you can handle any kind of "context" in a generic way, e.g. async calls, error handling, audit logging, software transactional memory, or custom things for e.g. database access. F# has a number of these specific implementations but they're kind of "hard-coded" in the language rather than fully extensible. So I guess the pitch is: imagine C# async/await could be "just a library", and other contexts that you wanted to handle similarly could also be a library, and the resulting functions are first-class citizens in the type system (no awkward choices of whether a particular function is async or not, you can handle that generically).
- Locke1689 12y agoSo I guess the pitch is: imagine C# async/await could be "just a library", and other contexts that you wanted to handle similarly could also be a library, and the resulting functions are first-class citizens in the type system (no awkward choices of whether a particular function is async or not, you can handle that generically). That's true in F# -- async is just a library in a computation expression.
- yohanatan 12y ago> F# has a number of these specific implementations but they're kind of "hard-coded" in the language rather than fully extensible. That's not true. You can extend the language yourself with "computation expressions" (and that's in fact how the 'async', 'let!' et al keywords are implemented).
- lmm 12y agoTrue, but what you can't do is abstract over them; you can't write a function that operates on "some generic computation expression" (you can't even write that type). So you can't write "sequence" or "traverseM" or more complicated/specific things you build on top of these.
- yohanatan 12y agoThere is an encoding supporting that level of abstraction (perhaps though not as straightforward as you'd prefer); namely using interfaces (which are first-class) to encode module signatures. See: https://gist.github.com/t0yv0/192353 https://gist.github.com/t0yv0/192353