lec11 - ( (* Dan Grossman, Spring 2008, CSE341 lecture 11...

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

View Full Document Right Arrow Icon
(* Dan Grossman, Spring 2008, CSE341 lecture 11 *) ( (* this signature hides gcd and reduce. That way clients cannot assume they exist or call them with inputs that cause infinite loops. *) signature RATIONAL_A = sig datatype rational = Frac of int * int | Whole of int exception BadFrac val make_frac : int * int -> rational val add : rational * rational -> rational val toString : rational -> string end e (* the previous signature lets clients build any value of type rational they want by exposing the Frac and Whole constructors. This makes it impossible to maintain invariants about rationals, so add may go in an infinite loop and print_rat may print a non-reduced fraction. We fix this by making rational abstract. *) signature RATIONAL_B = sig type rational (* type now abstract *) exception BadFrac val make_frac : int * int -> rational val add : rational * rational -> rational val toString : rational -> string end e (* if we supported nonpositive numbers, but still wanted the invariant that all fractions were reduced, we could expose the Whole constructor
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/12/2009 for the course CSE 341 taught by Professor Staff during the Spring '08 term at University of Washington.

Page1 / 4

lec11 - ( (* Dan Grossman, Spring 2008, CSE341 lecture 11...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online