An amazing functional
- 29 July 2010
- Computation, News
Martin Escardo and Paulo Oliva have been working on the selection monad and related functionals. The selection monad `S(X) = (X -> R) -> X` is a cousin of the continuation monad `C(X) = (X -> R) -> R` and it has a lot of useful and surprising applications. I recommend their recent paper “What Sequential Games, the Tychonoff Theorem and the Double-Negation Shift have in Common” which they wrote for MSFP 2010 (if you visit the workshop you get to hear Martin live). They explain things via examples written in Haskell, starting off with the innocently looking functional `ox` (which i I am writting as ox
in Haskell for “crossed O”):
ox :: [(x -> r) -> x] -> ([x] -> r) -> [x] ox [] p = [] ox (e : es) p = a : ox es (p . (a:)) where a = e (\x -> p (x : ox es (p . (x:))))
It is just four lines of code, so how complicated could it be? Well, read the paper to find out. If you are ready for serious math, have a look at this paper instead.
andrejbauer@mathstodon.xyz
, I will
gladly respond.
You are also welcome to contact me directly.
Comments
Not only that. Given the type, I expect that if you have the Monad instance defined, ox is one line:
@Dan: Yes of course, but that doesn't look as cool, does it :-) ?
Awesome!
A small remark: I think the remark on laziness of
p True
versusif p True then True else False
is nonsense. Both have the same behavior: they are strict inp
, because forcing either expression will forcep
as well.Maybe you're thinking of a strict-by-default semantics with suspensions along the lines of
Lazy (p True)
versusif p True then Lazy True else Lazy False
, but that's not how it happens in Haskell.