Mathematics and Computation

A blog about mathematics for computers

An amazing functional

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.


Dan Doel

Not only that. Given the type, I expect that if you have the Monad instance defined, ox is one line:

ox = sequence :: [S r x] -> S r [x]

@Dan: Yes of course, but that doesn't look as cool, does it :-) ?

Heinrich Apfelmus


A small remark: I think the remark on laziness of p True versus if p True then True else False is nonsense. Both have the same behavior: they are strict in p, because forcing either expression will force p as well.

Maybe you're thinking of a strict-by-default semantics with suspensions along the lines of Lazy (p True) versus if p True then Lazy True else Lazy False, but that's not how it happens in Haskell.

How to comment on this blog: At present comments are disabled because the relevant script died. If you comment on this post on Mastodon and mention, I will gladly respond. You are also welcome to contact me directly.