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 Itera@ve 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 un@l now: The closure of the local recursive func@on loop includes a binding for the loop func@on itself! Why? The loop body men@ons the loop iden@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

Ask a homework question - tutors are online