News for hackers. Stuff that matters.
Re:Implementing Algebraic Effects in C by frankpf on Sunday July 30, 2017 @07:21PM (#14888419)
A little off-topic, but the author of this paper (Daan Leijen) is also the author of Koka[1], a programming language with algebraic effects.

IMO, Koka (or something similar) has more potential to become a mainstream language than "traditional" FP languages (Haskell, OCaml, Idris, etc.).

Effects seem to be easier to understand than monads (at least on a superficial level) and more modular (I don't have a lot of experience with Haskell, so take that with a grain of salt).

Its syntax is also very close to C-like languages.

Taken from the Koka book[2]:

  fun square1(x : int) : total int {
    return x*x
  }

  fun square2(x : int) : io int {
    println( "a not so secret side-effect" )
    return x*x
  }
`square1` is a pure mathematical function, so its effect is `total`. `square2` has a side-effect because of `println`, so its effect is `io`. This means that `square2` can raise exceptions, not terminate, be non-deterministic, read and write to the heap, and do any input/output operations.

Note that Koka can infer effects, so these annotations are optional.

[1]: https://www.microsoft.com/en-us/research/project/koka/?from=...

[2]: https://koka-lang.github.io/koka/doc/kokaspec.html#sec-effec...

Re:Implementing Algebraic Effects in C by chenglou on Sunday July 30, 2017 @09:57PM (#14889011)
Fwiw, OCaml algebraic effects are being implemented: http://kcsrk.info/ocaml/multicore/2015/05/20/effects-multico...

(And then there's https://reasonml.github.io, which I work on)

Re:Implementing Algebraic Effects in C by frankpf on Monday July 31, 2017 @12:28AM (#14889458)
Hey there, Reason is a great project! Thanks for working on it!

I actually tried to use it very recently in a new project at my workplace, but unfortunately I decided not to. I found some fundamental things were lacking.

I didn't find documentation about how to interact with npm libraries (e.g. how do I use a websockets library in Reason? Do I have to create my own bindings? If so, how?).

There also seemed to be nothing similar to async/await in Reason/Bucklescript yet and I couldn't find out how to use promises.

I'll definitely reevaluate it in the future. I think it is an awesome project with great potential (along with Bucklescript which is awesome too).

Re:Implementing Algebraic Effects in C by chenglou on Monday July 31, 2017 @05:13PM (#14895941)
Late reply, but we have such guide here: https://reasonml.github.io/guide/javascript/converting

You can also check the community's work: https://reasonml.github.io/community/

Re:Implementing Algebraic Effects in C by lmm on Monday July 31, 2017 @06:59AM (#14890863)
I find monads much much more easy to reason about, because they give you a "plain old values" perspective as well as an effectful perspective; most of the time you work like you would with effects, but if you ever get confused you can drop down to seeing what the values are doing. The one mainstream example of something effect-like is Java checked exceptions, which are widely regarded as a failure (and I think for good reason).
Re:Implementing Algebraic Effects in C by zengid on Monday July 31, 2017 @02:59PM (#14894924)
Cool talk by Leijen about Koka and algebraic-effects: https://youtu.be/hrBq8R_kxI0
Re:Implementing Algebraic Effects in C by nwmcsween on Monday July 31, 2017 @01:24AM (#14889656)
My dream for a language is a type system that can enforce runtime semantics, preferably at import.

  import 'mod::memcmp': O(1);
where O(1) is big O notation.
Re:Implementing Algebraic Effects in C by adrianN on Monday July 31, 2017 @07:20AM (#14890922)
That would be a very restrictive programming environment, or type checking might fail or produce ridiculously large runtime bounds. It is not decidable whether a given Turing machine has runtime O(n^k) for a particular k, even if you're given the promise that such a k exists.
Re:Implementing Algebraic Effects in C by tmzt on Monday July 31, 2017 @01:41PM (#14894252)
Could you make it an attribute of the symbol being exported, part of the contract, and use that to derive an estimated cost of the program?

I could see this being used to choose between allocators or schedulers given specific requirements.

Re:Implementing Algebraic Effects in C by mrkgnao on Monday July 31, 2017 @04:39AM (#14890366)