Ordered from head to tail let tolist q a queue a

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: gt; len! | Some n -> loop n.next (1+len)! 67 end! ! Tail Calls and Itera@ve length Workspace begin match no with! | None -> len! | Some n -> loop n.next (1+len)! end! Stack length q Heap fun (q:'a queue) ->! let rec loop (no:…) (len:int)=! …! in! loop q.head 0! loop no head! tail! len 2! Note: Again, the tail call leaves the stack as before, but effec@vely updates the values of no and len. We may as well call this in- place- update of the stack, even though technically these bindings are not mutable! CIS120 / Spring 2012 v! 1! next! v! next! 2! None! loop fun (no:'a qnode option) (len:int) -> begin match no with! | None -> len! | Some n -> loop n.next (1+len)! 68 end! ! Tail Calls and Itera@ve length Workspace begin match with! | None -> len! | Some n -> loop n.next (1+len)! end! Stack length q Heap fun (q:'a queue) ->! let rec loop (no:…) (len:int)=! …! in! loop q.head...
View Full Document

Ask a homework question - tutors are online