2

Continuations are interesting. Especially interesting is how they encompass all other monads. Also, I hear they are used a lot for optimizing. One thing I hear they could be used for is inversion of control in things. Like, gui's and stuff. I am wondering if there is an example of a library in Haskell that uses this.

I'm not particularly interested in it being popular or anything. I mainly want it for reading. Factors to consider:

  • Straight continuations, not continuation derivatives: It should be based on a type similar to newtype Cont r a = Cont ((a -> r) -> r). (Combinators are okay, but it should be understandable how straight continuations are fitting into it.)
  • Used for inversion of control: Continuations are used for many uses, but I'm interested mostly in GUI type things or other places where inversion of control makes things easier
  • Prevalence: Continuations should be the prevalent control structure.
  • Well written: Code should be easier to read and learn from.

(The reason why I want to do this is I find Continuations, being based only on functions, to be a very pure functional programming concept, while being very powerful. There is this one library I like that is very straight functional programming, and I would love to extend it with continuations.)

Note: Being straight continuations isn't very important. Inversion of Control is what I'm mostly after.

PyRulez
  • 10,513
  • 10
  • 42
  • 87
  • 5
    I have not seen many uses of straight continuations... anywhere. There are a lot of derivatives. I don't find the derivatives to be any less pure -- almost everything in Haskell is some combination of products, coproducts, and functions (and products and coproducts can be modeled using functions). – luqui Nov 02 '15 at 23:54
  • @luqui And type classes (type classes is the one thing I dislike about Haskell. They are done poorly in Haskell.) – PyRulez Nov 03 '15 at 00:13
  • 2
    This might interest you: http://www.thev.net/PaulLiu/invert-inversion.html – Aadit M Shah Nov 03 '15 at 00:20
  • a _"very pure functional programming concept, while being very powerful"_ is also FRP, in case you might be interested; I don't think continuations are something to be too keen on _per se_. – Erik Kaplun Nov 03 '15 at 00:40
  • 4
    Can you define what you mean by "inversion of control"? I've mostly heard that term used disparagingly to describe the soupy quality of callback-heavy code – jberryman Nov 03 '15 at 01:46
  • 5
    @PyRulez, many of us think Haskell type classes are the only ones done right. See Edward Kmett's video [Type classes vs. the World](https://www.google.com/url?q=http://m.youtube.com/watch%3Fv%3DhIZxTQP1ifo&sa=U&ved=0CAsQtwIwAGoVChMIpMewsaDzyAIVQ0AmCh2FggtT&sig2=bcftOWg7Nss7tTVBe9s4lg&usg=AFQjCNEBMR2fT2mxOniLf-UI6dBxz_hnaA). – dfeuer Nov 03 '15 at 02:56
  • Also, "pure" continuation passing (as with `Cont`) is much less useful than its "impure" forms (`ContT`). The same is true in, e.g., Scheme, where continuations are used to implement imperative-style control structures. – dfeuer Nov 03 '15 at 03:00
  • @dfeuer I don't mean pure in the technical sense. `ContT` is just a specialization of `Cont`. – PyRulez Nov 03 '15 at 09:42
  • There's also a continuation-based FRP implementation (Yampa), and it has been used to do GUI stuff. Signal Functions are just functions with continuations that take the time since the last simulation as argument. Other than that, they are just what you expressed above. As part of my PhD I'm working on a more general version of Yampa and that might suit your purposes even better. Feel free to drop me a line and give more details, if you want :) Disclaimer: I am the maintainer of Yampa. – Ivan Perez Nov 05 '15 at 13:45

0 Answers0