none len some n loop nnext 1len end stack

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t rec loop (no:…) (len:int)=! …! in! loop q.head 0! q head! tail! v! Note: (1)  No workspace is saved – there is no need do to that for tail calls (2)  We pop all the locals (up to the last saved workspace). In this case, there are none. CIS120 / Spring 2012 1! next! v! 2! next! 46 Tail Calls and [email protected] length Workspace (loop q.head 0)! Stack length q Heap fun (q:'a queue) ->! let rec loop (no:…) (len:int)=! …! in! loop q.head 0! q loop A detail we’ve been sweeping under the rug [email protected] now: The closure of the local recursive [email protected] loop includes a binding for the loop [email protected] itself! Why? The loop body [email protected] the loop [email protected]fier. CIS120 / Spring 2012 head! tail! v! 1! next! v! 2! next! loop fun (no:'a qnode option) (len:int) -> begin match no with! | None -> len! | Some n...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online