Hi Al,

What combination of

* define-record-type (srfi-9, srfi-99, chicken define-record, whatever) and

* (declare type ...)

can I use to inform the compiler that (for collections of myrec) vector- ref returns myrec's (likewise list car/cdr, hash-table-ref)? And that it needs not emit any instance-type-checking code for objects extracted from such collections?

For "native" Scheme types, there's at least `list-of` and `vector-of` [0]. The type definitions of car/cdr, vector-ref, etc are in the file types.db (you can find it at $PREFIX/lib/chicken/11/types.db).

For other data-structures you have to look at the specific implementation. For example, SRFI-69 [1] mentions types in the changelog. They're not mentioned in the docs, however, so you'll have to dig through the code to confirm this.

Separately, how can I tell the compiler that fields in these records have certain types? Add type declarations for the implicitly-defined per-field accessors and mutators?

To annotate the types of the fields of a record, take a look at defstruct[2]. There may be other alternatives, I only know of this one.


[0] https://wiki.call-cc.org/man/5/Types#type-syntax
[1] https://wiki.call-cc.org/eggref/5/srfi-69
[2] https://wiki.call-cc.org/eggref/5/typed-records#defstruct

Good luck!
siiky



Reply via email to