Stack length q heap fun qa queue let rec loop 3

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: p q.head 0! loop This binding comes from the closure. no head! tail! len 0! v! Notes: - no workspace is saved on the stack - pop the old locals (q and loop) - push the closure and argument bindings - the new workspace is just the body of the [email protected] CIS120 / Spring 2012 1! next! v! 2! next! loop fun (no:'a qnode option) (len:int) -> begin match no with! | None -> len! | Some n -> loop n.next (1+len)! 50 end! ! Tail Calls and [email protected] 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 0! loop no head! tail! len 0! v! 1! next! v! 2! next! loop CIS120 / Spring 2012 fun (no:'a qnode option) (len:int) -> begin match no with! | None -> len! | Some n -> loop n.next (1+len)! 51 end! !...
View Full Document

This document was uploaded on 11/24/2013.

Ask a homework question - tutors are online