{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes43 - • Orthogonality of types and operators The next...

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: • Orthogonality of types and operators. The next problem to deal with is the proliferation of functions because you want to be able to apply every operation to every type. In our example, with two types and two operations we need four algorithms. What happens when we invent a new type? If we write our program in the conventional (i.e., old-fashioned) style as above, it’s not enough to add new functions; we have to modify all the operator functions like area to know about the new type. We’ll look at two different approaches to organizing things better: data-directed programming and message passing . The idea in DDP is that instead of keeping the information about types versus operators inside functions, as cond clauses, we record this information in a data structure. A&S provide tools put to set up the data structure and get to examine it: > (get ’foo ’baz) #f > (put ’foo ’baz ’hello) > (get ’foo ’baz) hello Once you put something in the table, it stays there. (This is our first departure from functional programming.something in the table, it stays there....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online