29.01.2014 Views

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 8. DEPENDANT TYPE QUALIFIERS 61<br />

let exactRGBStr = "ExactRGB"<br />

let lowerRGBStr = "LowerRGB"<br />

let upperRGBStr = "UpperRGB"<br />

let color strings = [exactRGBStr; lowerRGBStr; upperRGBStr; ]<br />

The next four functions, leading up to string <strong>of</strong> colors assist in turning a list <strong>of</strong> colors into a<br />

string. The function rgb <strong>of</strong> color returns the rgb tuple used in a color.<br />

let rgb <strong>of</strong> color (c : color) : rgb =<br />

match c with<br />

| ExactRGB(r, g, b)<br />

| LowerRGB(r, g, b)<br />

| UpperRGB(r, g, b) → r, g, b<br />

The function string <strong>of</strong> rgb uses triplemap (dened in Tututil) to convert the elements <strong>of</strong> an<br />

rgb tuple to Pretty.docs, and then to strings with Pretty.sprint.<br />

let string <strong>of</strong> rgb (t : rgb) : string =<br />

let t =<br />

t | > triplemap (d exp ())<br />

|> triplemap (sprint £width : 80)<br />

in<br />

"("¢(fst3 t)¢", "¢(snd3 t)¢", "¢(thd3 t)¢")"<br />

The function string <strong>of</strong> color uses string <strong>of</strong> rgb to convert a color to a string<br />

let string <strong>of</strong> color (c : color) : string =<br />

let k =<br />

match c with<br />

| ExactRGB → exactRGBStr<br />

| LowerRGB → lowerRGBStr<br />

| UpperRGB → upperRGBStr<br />

in<br />

k¢(c | > rgb <strong>of</strong> color | > string <strong>of</strong> rgb)<br />

The function string <strong>of</strong> colors converts a list <strong>of</strong> colors into a comma separated string.<br />

let string <strong>of</strong> colors (c : colors) : string =<br />

c<br />

|> L.map string <strong>of</strong> color<br />

|> S.concat ", "

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!