1 util
cast
exact-round
exact-floor
exact-ceiling
exact-truncate
2 list
remf
interleave
replace-at
remove-at
all-but-last
3 lang/ posn
Posn
make-posn
posn?
posn-x
posn-y
4 2htdp/ image
Image
Nat
Angle
Color
Image-Color
Mode
X-Place
Y-Place
Pen
Pen-Style
Pen-Cap
Pen-Join
circle
ellipse
triangle
right-triangle
isosceles-triangle
square
rectangle
rhombus
regular-polygon
star
star-polygon
polygon
line
add-line
add-curve
text
text/ font
overlay
overlay/ align
overlay/ xy
underlay
underlay/ align
underlay/ xy
beside
beside/ align
above
above/ align
empty-scene
place-image
place-image/ align
scene+ line
scene+ curve
rotate
scale
scale/ xy
crop
frame
image?
image-width
image-height
image-baseline
mode?
image-color?
color?
make-color
color-red
color-green
color-blue
y-place?
x-place?
angle?
side-count?
pen?
make-pen
pen-color
pen-width
pen-style
pen-cap
pen-join
pen-style?
pen-cap?
pen-join?
hspace
vspace
above0
beside0
beside/ align0
5 2htdp/ universe
animate
6 Testing

Typed: Libraries and Utilities

David Van Horn <dvanhorn@ccs.neu.edu>

This package contains a set of typed libraries. It is still under development.

Report a bug.

1 util

 (require (planet dvanhorn/typed:1:5/util))

cast : (All (T) ((Any -> Boolean : T) Any -> T))
Cast the given value to the type described by the predicate. Note the predicate must be symmetric. The cast will fail at run-time if the value does not satisfy the predicate.

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

These operations coerce their result to exact integers.

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:

  

    (file

    

  /Users/dvanhorn/Documents/planet/typed/util.ss)

   broke the

  contract (-> rational? any/c) on exact-round; expected

  <rational?>, given: +inf.0

2 list

 (require (planet dvanhorn/typed:1:5/list))

remf : (All (X) ((X -> Boolean) [Listof X] -> [Listof X]))
Remove the first element satisfying the given predicate (if any).

Example:

  > (remf even? '(1 3 2 5 4))

  - : (Listof Exact-Positive-Integer)

  (1 3 5 4)

interleave : (All (X) (X [Listof X] -> [Listof X]))
Interleave given element between each pair of elements in list.

Examples:

  > (interleave '* '())

  - : (Listof '*)

  ()

  > (interleave '* '(x y z))

  - : (Listof (U '* 'x 'y 'z))

  (x * y * z)

replace-at : (All (X) ([Listof X] X Nat -> [Listof X]))
remove-at : (All (X) ([Listof X] Nat -> [Listof X]))

Examples:

  > (replace-at '("a" "b" "c") "z" 1)

  - : (Listof String)

  ("a" "z" "c")

  > (remove-at '("a" "b" "c") 1)

  - : (Listof String)

  ("a" "c")

all-but-last : (All (X) ((Pair X (Listof X)) -> (Listof X)))
Given a non-empty list, returns a list of all but the last element.

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.

Posn constructor, predicate, and accessors.

4 2htdp/image

 (require (planet dvanhorn/typed:1:5/2htdp/image))

This module provides a typed variant of the 2htdp/image library.

Base types.

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"

circle : (Real Mode (U Pen Image-Color) -> Image)
ellipse : (Real Real Mode (U Pen Image-Color) -> Image)
triangle : (Real Mode (U Pen Image-Color) -> Image)
right-triangle : (Real Real Mode (U Pen Image-Color) -> Image)
isosceles-triangle : (Real Angle Mode (U Pen Image-Color) -> Image)
square : (Real Mode (U Pen Image-Color) -> Image)
rectangle : (Real Real Mode (U Pen Image-Color) -> Image)
rhombus : (Real Angle Mode (U Pen Image-Color) -> Image)
regular-polygon : (Real Nat Mode (U Pen Image-Color) -> Image)
star : (Real Mode (U Pen Image-Color) -> Image)
star-polygon : (Real Nat Nat Mode (U Pen Image-Color) -> Image)
polygon : ([Listof Posn] Mode (U Pen Image-Color) -> Image)
line : (Real Real Image-Color -> Image)
add-line : (Image Real Real Real Real (U Pen Image-Color) -> Image)
add-curve : 
(Image Real Real Angle Real Real Real Angle Real
       (U Pen Image-Color) -> Image)
text : (String Integer Image-Color -> Image)
text/font : 
(String Exact-Positive-Integer Image-Color (Option String)
        (U 'default 'decorative 'roman 'script
           'swiss 'modern 'symbol 'system)
        (U 'normal 'italic 'slant)
        (U 'normal 'bold 'light)
        Any
        -> Image)
overlay : (Image Image Image * -> Image)
overlay/align : (X-Place Y-Place Image Image Image * -> Image)
overlay/xy : (Image Real Real Image -> Image)
underlay : (Image Image Image * -> Image)
underlay/align : (X-Place Y-Place Image Image Image * -> Image)
underlay/xy : (Image Real Real Image -> Image)
beside : (Image Image Image * -> Image)
beside/align : (Y-Place Image Image Image * -> Image)
above : (Image Image Image * -> Image)
above/align : (X-Place Image Image Image * -> Image)
empty-scene : (Real Real -> Image)
place-image : (Image Real Real Image -> Image)
place-image/align : (Image Real Real X-Place Y-Place Image -> Image)
scene+line : (Image Real Real Real Real (U Pen Image-Color) -> Image)
scene+curve : 
(Image Real Real Angle Real Real Real Angle Real
       (U Pen Image-Color) -> Image)
rotate : (Angle Image -> Image)
scale : (Real Image -> Image)
scale/xy : (Real Real Image -> Image)
crop : (Real Real Real Real Image -> Image)
frame : (Image -> Image)
image? : (Any -> Boolean : Image)
image-width : (Image -> Nat)
image-height : (Image -> Nat)
image-baseline : (Image -> Nat)
mode? : (Any -> Boolean : Mode)
image-color? : (Any -> Boolean : Image-Color)
color? : (Any -> Boolean : Color)
make-color : (Nat Nat Nat -> Color)
color-red : (Color -> Nat)
color-green : (Color -> Nat)
color-blue : (Color -> Nat)
y-place? : (Any -> Boolean : Y-Place)
x-place? : (Any -> Boolean : X-Place)
angle? : (Any -> Boolean)
side-count? : (Any -> Boolean)
pen? : (Any -> Boolean : Pen)
make-pen : (Image-Color Real Pen-Style Pen-Cap Pen-Join -> Pen)
pen-color : (Pen -> Image-Color)
pen-width : (Pen -> Real)
pen-style : (Pen -> Pen-Style)
pen-cap : (Pen -> Pen-Cap)
pen-join : (Pen -> Pen-Join)
pen-style? : (Any -> Boolean : Pen-Style)
pen-cap? : (Any -> Boolean : Pen-Cap)
pen-join? : (Any -> Boolean : Pen-Join)
Typed variants of the image teachpack.

Additionally, the library defines the following:

Creates an image of 0 height and given width.
Creates an image of 0 width and given height.

above0 : (Image * -> Image)
Extension of above to zero- and un-ary case.
Extension of beside to zero- and un-ary case.
Extension of beside/align to zero- and un-ary case.

5 2htdp/universe

 (require (planet dvanhorn/typed:1:5/2htdp/universe))

This module provides a typed variant of the 2htdp/universe library.

animate : ((Nat -> Image) -> Nat)
Typed animate.

6 Testing

 (require (planet dvanhorn/typed:1:5/run-tests))

Requiring this module will run all of the unit tests for this package.