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.

3 thoughts on “An amazing functional

  1. 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]

  2. Awesome!

    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.

Leave a Reply to Heinrich Apfelmus Cancel reply

Your email address will not be published. Required fields are marked *

*