From: jim Date: Sun, 8 Mar 2015 03:05:04 +0000 (-0500) Subject: tweak explanation X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=7c7072d47d231e4d4f86b229fb3877d1c3f921e2 tweak explanation --- diff --git a/exercises/assignment5_hint4.mdwn b/exercises/assignment5_hint4.mdwn index 7ef02c6a..498d7b3b 100644 --- a/exercises/assignment5_hint4.mdwn +++ b/exercises/assignment5_hint4.mdwn @@ -176,7 +176,7 @@ If we just decline to specify the types, OCaml will infer them for us: let sysf_cons x xs = fun c n -> fun () -> c x (xs c n);; let sysf_length xs = xs (fun x z -> z () + 1) (fun () -> 0) ();; -Notice that we have `sysf_cons` returning a `fun () ->`, and also that in `sysf_length` we have to apply a `()` to the seed argument to evaluate it and extract its value, and also we apply a `()` to the output of the `sysf_length` function. +Notice that we have `sysf_cons` returning a `fun () ->`, and also that in `sysf_length` we have to apply a `()` to the seed argument to evaluate it and extract its value. That's a good thing, we don't *want* to automatically evaluate the fold over the rest of the list if doing so might invoke a `blackhole` or `failwith`. We only want the fold over the rest of the list to be evaluated when we specifically request it, by feeding the thunk a `()` argument. (This is called "forcing the thunk.") Also, after the fold has traversed the whole list, what we'll have at that point will be a thunk (it has to have the same type as the seed value). So we have to force it to get our answer --- that's why there's a `()` at the end of `sysf_length`. Now how are we doing?