{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec8 Modules and Signatures

# lec8 Modules and Signatures - 1 CSE 130 Fall 2006...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 1 CSE 130 : Fall 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 8: Modules and Signatures Previously: Polymorphism enables Reuse • Can reuse generic functions: map :’a * ’b → ’b * ’a filter : (’a → bool * ’a list) → ’a list rev : ’a list → ’a list length : ’a list → int swap : ’a * ’b → ’b * ’a sort: (’a → ’a → bool * ’a list) → ’a list compose: (’a → ’b * ’c → ’b) → ’c → ’a • If function (algorithm) is “independent” of type, can reuse code for all types ! Today: Divide-Conquer Programming • We’ve seen very small programs so far – 4 yr education chopped into quarters • Typical software is thousands, millions LOC • How can a PL help to manage complexity ? – Only one technique humans know about Rational Numbers • Say you want a software package that uses rational numbers heavily • Remember rationals ? – Ratio of two integers: m/n • Well, seems simple enough: – Use a pair of integers to represent rationals! – OCaml type: int * int Rational Numbers • Well, every pair of isn’t a rational… – (5,0) ? – 2nd elem “denominator” must not be zero • How do we print a rational ? • When are two rationals “equal” ? – (6,4) and (30,20) ? – Need to normalize rationals – But need to fix to_string Many functions related to type Pack into a module • Types, Values, Exceptions bound in Name are : – Name.t, Name.x , Name.f • Bind module to diff name module Name = struct bindings end module NewName = Rational;; NewName.add;; … NewName.to_string;; … 2...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

lec8 Modules and Signatures - 1 CSE 130 Fall 2006...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online