6.6 Types, Predicates and Accessors
syntax
(Array A)
> (define arr (array #[1 2 3 4 5]))
> arr eval:83:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr24
in: arr
> (ann arr (Array Real)) eval:84:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr24
in: Real
> (ann arr (Array Any)) eval:85:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr24
in: Any
> (define arr (mutable-array #[1 2 3 4 5]))
> arr eval:87:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr25
in: arr
> (ann arr (Array Real)) eval:88:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr25
in: Real
> (ann arr (Array Any)) eval:89:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr25
in: Any
syntax
(Settable-Array A)
> (define arr (mutable-array #[1 2 3 4 5]))
> arr eval:91:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr26
in: arr
> (ann arr (Settable-Array Integer)) eval:92:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr26
in: Integer
> (ann arr (Settable-Array Real)) eval:93:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr26
in: Real
syntax
(Mutable-Array A)
> (define arr (mutable-array #[#[1 2] #[3 4]]))
> (vector-set! (mutable-array-data arr) 0 -10)
eval:95:0: Type Checker: missing type for top-level identifier;
either undefined or missing a type annotation
identifier: arr27
in: -10
context...:
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form
fail-to-succeed
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4
/Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop
eval:95:0: Type Checker: missing type for top-level identifier;
either undefined or missing a type annotation
identifier: arr27
in: -10
context...:
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form
fail-to-succeed
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4
/Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop
Type Checker: Summary: 2 errors encountered
> arr eval:96:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr27
in: arr
syntax
Example: | |||
|
syntax
Examples: | |||||||||||||||
|
This makes indexes-accepting functions easier to use, because it is easier to convince Typed Racket that a vector contains Integer elements than that a vector contains Index elements.
> (define js ((inst vector Index) 3 4 5))
> js eval:102:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: js29
in: js
> (ann js (Vectorof Integer)) eval:103:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: js29
in: Integer
> (ann js In-Indexes) eval:104:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: js29
in: In-Indexes
procedure
v : Any
procedure
(settable-array? v) → Boolean
v : Any
procedure
(mutable-array? v) → Boolean
v : Any
> (: maybe-array-data (All (A) ((Array A) -> (U #f (Vectorof A)))))
> (define (maybe-array-data arr) (cond [(mutable-array? arr) (mutable-array-data arr)] [else #f])) eval:106:0: Type Checker: Polymorphic function
`mutable-array-data' could not be applied to arguments:
Argument 1:
Expected: (Mutable-Array A)
Given: (Struct Mutable-Array)
in: #f
> array? - : (-> Any Boolean : (Array Any))
#<procedure:Array?>
> settable-array? - : (-> Any Boolean : (Struct Settable-Array))
#<procedure:Settable-Array?>
> mutable-array? - : (-> Any Boolean : (Struct Mutable-Array))
#<procedure:Mutable-Array?>
procedure
(array-shape arr) → Indexes
arr : (Array A)
Examples: | ||||||||||||
|
procedure
(array-size arr) → Index
arr : (Array A)
Examples: | ||||||||||||
|
procedure
(array-dims arr) → Index
arr : (Array A)
procedure
(mutable-array-data arr) → (Vectorof A)
arr : (Mutable-Array A)