Typed: Libraries and Utilities
David Van Horn <dvanhorn@ccs.neu.edu>
This package contains a set of typed libraries. It is still under development.
1 util
(require (planet dvanhorn/typed:1:5/util)) |
Casting is useful to embed type refinements the programmer can prove that Typed Scheme is not able to reason about.
Examples: |
> (sin pi) |
- : Number |
1.2246467991473532e-16 |
> (cast real? (sin pi)) |
- : Real |
1.2246467991473532e-16 |
> (cast string? 5) |
Cast failed |
| |
| |
| |
|
Examples: |
> (round 3/2) |
- : Real |
2 |
> (exact-round 3/2) |
- : Integer |
2 |
> (round 2.5) |
- : Real |
2.0 |
> (exact-round 2.5) |
- : Integer |
2 |
It is a contract violation to apply these operations to a non-rational real (i.e., +inf.0, -inf.0, or +nan.0), since there is no exact representation of these values.
Examples: | |||
> (round +inf.0) | |||
- : Real | |||
+inf.0 | |||
> (exact-round +inf.0) | |||
/Users/dvanhorn/Documents/planet/typed/private/util.ss:2.19: | |||
| |||
| |||
contract (-> rational? any/c) on exact-round; expected | |||
<rational?>, given: +inf.0 |
2 list
(require (planet dvanhorn/typed:1:5/list)) |
Example: |
> (remf even? '(1 3 2 5 4)) |
- : (Listof Exact-Positive-Integer) |
(1 3 5 4) |
interleave : (All (X) (X [Listof X] -> [Listof X])) |
Examples: |
> (interleave '* '()) |
- : (Listof '*) |
() |
> (interleave '* '(x y z)) |
- : (Listof (U '* 'x 'y 'z)) |
(x * y * z) |
| |
|
Examples: |
> (replace-at '("a" "b" "c") "z" 1) |
- : (Listof String) |
("a" "z" "c") |
> (remove-at '("a" "b" "c") 1) |
- : (Listof String) |
("a" "c") |
Examples: |
> (all-but-last '(x)) |
- : (Listof 'x) |
() |
> (all-but-last '(x y z)) |
- : (Listof (U 'x 'y 'z)) |
(x y) |
3 lang/posn
(require (planet dvanhorn/typed:1:5/lang/posn)) |
This module provides a typed variant of the lang/posn library.
| |
| |
| |
|
4 2htdp/image
(require (planet dvanhorn/typed:1:5/2htdp/image)) |
This module provides a typed variant of the 2htdp/image library.
Image, Color, and Pen are opaque types with predicates image?, color?, and pen?, respectively.
Angle is a synonym for Real and Nat for Exact-Nonnegative-Integer.
Image-Color is (U Color String Symbol) and the image-color? procedure is its predicate.
Mode is (U 'solid "solid" 'outline "outline") and the mode? procedure is its predicate.
Example: |
> (cast mode? "outline") |
- : Mode |
"outline" |
X-Place is (U 'left 'right 'middle 'center "left" "right" "middle" "center") and the x-place? procedure is its predicate.
Example: |
> (cast x-place? "left") |
- : X-Place |
"left" |
Y-Place is (U 'top 'bottom 'middle 'center 'baseline "top" "bottom" "middle" "center" "baseline") and the y-place? procedure is its predicate.
Example: |
> (cast y-place? "baseline") |
- : Y-Place |
"baseline" |
Pen-Style is (U "solid" 'solid "dot" 'dot "long-dash" 'long-dash "short-dash" 'short-dash "dot-dash" 'dot-dash) and the pen-style? procedure is its predicate.
Example: |
> (cast pen-style? "dot") |
- : Pen-Style |
"dot" |
Pen-Cap is (U "round" 'round "projecting" 'projecting "butt" 'butt) and the pen-cap? procedure is its predicate.
Example: |
> (cast pen-cap? "butt") |
- : Pen-Cap |
"butt" |
Pen-Join is (U "round" 'round "bevel" 'bevel "miter" 'miter) and the pen-join? procedure is its predicate.
Example: |
> (cast pen-join? "bevel") |
- : Pen-Join |
"bevel" |
Additionally, the library defines the following:
beside/align0 : (Image * -> Image) |
5 2htdp/universe
(require (planet dvanhorn/typed:1:5/2htdp/universe)) |
This module provides a typed variant of the 2htdp/universe library.
6 Testing
(require (planet dvanhorn/typed:1:5/run-tests)) |
Requiring this module will run all of the unit tests for this package.