X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=week11.mdwn;fp=week11.mdwn;h=b2ab88dea65a66e1e81c1197adaa9911129fdb37;hp=1857d8b988836b22dc691e2238a5d69e6cf9e65a;hb=8e50e0b21cef6e6d5aba8265bf2aa0adbf6647d2;hpb=21d43bf1749e0f6329a481ab8d4c5726a13e7011 diff --git a/week11.mdwn b/week11.mdwn index 1857d8b9..b2ab88de 100644 --- a/week11.mdwn +++ b/week11.mdwn @@ -3,20 +3,11 @@ The material here benefited from many discussions with Ken Shan. [[!toc]] -##List Zippers## +##[[Tree and List Zippers]]## -Say you've got some moderately-complex function for searching through a list, for example: +##[[Coroutines and Aborts]]## - let find_nth (test : 'a -> bool) (n : int) (lst : 'a list) : (int * 'a) -> - let rec helper (position : int) n lst = - match lst with - | [] -> failwith "not found" - | x :: xs when test x -> (if n = 1 - then (position, x) - else helper (position + 1) (n - 1) xs - ) - | x :: xs -> helper (position + 1) n xs - in helper 0 n lst;; +##[[From Lists to Continuations]]## This searches for the `n`th element of a list that satisfies the predicate `test`, and returns a pair containing the position of that element, and the element itself. Good. But now what if you wanted to retrieve a different kind of information, such as the `n`th element matching `test`, together with its preceding and succeeding elements? In a real situation, you'd want to develop some good strategy for reporting when the target element doesn't have a predecessor and successor; but we'll just simplify here and report them as having some default value: @@ -1760,4 +1751,7 @@ called a that is intended to represent non-deterministic computations as a tree. +##[[List Monad as Continuation Monad]]## + +##[[Manipulating Trees with Monads]]##