5 ms·
A lot of commentors are mentioning that this is just a specific case of effect typing. Haskell and monads have been brought up as an example of effects typing,
by adrusi 12y ago
A lot of commentors are mentioning that this is just a specific case of effect typing. Haskell and monads have been brought up as an example of effects typing, but I'd like to present another example that more closely resemble familiar static type systems.
Nim[1], at least at one point (I'm looking at the current manual and can't find it documented), had support for tagging functions with a pragma and the compiler would enforce that functions without the pragma can't call function with the pragma outside of a special block. The compiler interpreted certain pragmas like "impure" and "exception" in a special way, outputting a warning when certain language features were used inside functions marked with the pragma. The language manual shows that the compiler still at least supports these special pragmas. It's possible that it never supported custom pragmas and I'm just misremembering.
Interestingly, the author dismisses promises as not a major improvement and calls async/await and generators at least a half-way solution. It turns out that the are just a simple syntactic transform that isn't powerful enough to express everything that coroutines can. Promises, on the other hand, can. Promises are actually a monad: `.then(...)` is the bind function (`>>=`). This is essentially how the IO monad in Haskell works.
[1]: https://nim-lang.org/ https://nim-lang.org/
- ufo 12y ago> It turns out that the are just a simple syntactic transform that isn't powerful enough to express everything that coroutines can. Sure, but at least with async/await you can reuse control flow structures from the original language, like for loops and try-catch. With promises you need to reimplement all of those as a library.
- tel 12y agoYou can recurse and branch just fine, you just lose for/while loops.
- munificent 12y agoRecursing can build up very long promise chains if you aren't careful and also just isn't a natural way for many programmers to express many kinds of code. Even simple branching gets nasty in many cases if, for example, one branch does something async while the other does not. You also lose try/catch.
- tel 12y agoYeah, agreed. It's functional, but technically weak. This might be a place to introduce functional pipelines like Haskell's Pipes, Machines, Conduits. They solve the effectfull iteration and streaming problem, but the mechanism is heavily transformer based.
- ufo 12y agoThe problem is that while you can introduce FP abstractions to structure your programs, they are not the same abstractions that you use in the synchronous (imperative) code. You still end up in a situation where your programs is written in two colors that don't play nice with one another (for example, a "foreach" combinator doesn't work on both sync callbacks and async callbacks)
- seanmcdirmid 12y agoAlso, what about Koka ? http://koka.codeplex.com/ http://koka.codeplex.com/ and http://research.microsoft.com/en-us/projects/koka/ http://research.microsoft.com/en-us/projects/koka/ From the latter: > The Koka project tries to see if effect inference can be used on larger scale programming. The language is strict (as in ML), but seperates pure values from side effecting computations (as in Haskell). Through the effect types, there is also a strong connection to its denotational semantics, where the effect type of each function has a direct translation to the type signature of the denotational function.
- tel 12y agoI just wanted to say that I've finally taken a look at Koka after hearing you mention in on HN many times. It's very nice! I appreciate how it provides most of the bang of effect types much more conveniently than one might expect with the explicit monadic structuring going on in Haskell. Have you looked at Frank [0] by any chance? It has a very similar row-effect type (I guess these were both first explored in Eff?) but in a CBPV language which makes it clear how pure values are separated from effectful computation. [0] http://homepages.inf.ed.ac.uk/slindley/papers/frankly-draft-march2014.pdf http://homepages.inf.ed.ac.uk/slindley/papers/frankly-draft-...
- seanmcdirmid 12y agoI'm not versed in this area, but I listen to Daan talk about Koka a lot. You might want to ask him directly about Frank.
- dom96 12y agoCustom pragmas in Nim are supported although I'm not sure they do what you're after. You may also be talking about Nim's effect tracking. Nim also supports async await. (I can't give you any links as I am on mobile right now)