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:4/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)) |
- : Number |
1.2246467991473532e-16 |
> (cast string? 5) |
Cast failed |
| |
| |
| |
|
Examples: |
> (round 3/2) |
- : Number |
2 |
> (exact-round 3/2) |
- : Integer |
2 |
> (round 2.5) |
- : Number |
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) | |||
- : Number | |||
+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 2htdp/image
(require (planet dvanhorn/typed:1:4/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) |
3 2htdp/universe
(require (planet dvanhorn/typed:1:4/2htdp/universe)) |
This module provides a typed variant of the 2htdp/universe library.