15. Bigloo -- Explicit typing

15. Bigloo -- Explicit typing

Browsing

Home: Bigloo
A ``practical Scheme compiler''
User manual for version 2.6c
March 2004

Previous chapter: Command Line Parsing
Next chapter: The C interface


Chapters

  Acknowledgements
1. Table of contents
2. Overview of Bigloo
3. Modules
4. Core Language
5. Standard Library
6. Pattern Matching
7. Object System
8. Threads
9. Regular parsing
10. Lalr(1) parsing
11. Errors and Assertions
12. Eval and code interpretation
13. Macro expansion
14. Command Line Parsing
15. Explicit typing
16. The C interface
17. The Java interface
18. Bigloo Libraries
19. Extending the Runtime System
20. SRFIs
21. DSSSL support
22. Compiler description
23. User Extensions
24. Bigloo Development Environment
25. Global Index
26. Library Index
  Bibliography

Bigloo supports type annotation or type information. As shown in Section ref Module declaration, these annotations can be written both in the module clauses and in module bodies although module body type information is optional. It helps the compiler to produce better quality code and to reject incorrectly typed programs. Type annotations can describe both the result and formal parameter types for global functions and also types for local variable. Due to our module language design (in particular module initialization), Scheme global variables cannot support type information.

Warning: All type annotations are ignore by the interpreter.

Module body type annotations are introduced by the following special forms.

define (f[::type] [a[::type]]...) bodybigloo syntax
define-inline (f[::type] [a[::type]]...) bodybigloo syntax
let ((var[::type] ...) ...) bodybigloo syntax
let loop ((var[::type] ...) ...) bodybigloo syntax
let* ((var[::type] ...) ...) bodybigloo syntax
letrec ((var[::type] ...) ...) bodybigloo syntax
labels ((var[::type] (var[::type]...) b) ...) bodybigloo syntax
Type annotations are optional. That is, for any of these constructions, if a type annotation is missing, Bigloo uses the default generic type obj instead.

Here is an example of type annotated program:

(module example
   (export (vector-fill!::vector ::vector ::obj)))

(define (vector-fill! v filler)
  (let loop ((i::long (- (vector-length v) 1)))
     (if (= i 0)
         v
         (begin
            (vector-set! v i filler)
            (loop (- i 1))))))

(let ((v::vector (make-vector 3 4)))
   (vector-fill! v "dummy"))
The types that can be used in annotations are any of:



When a function that contains type annotation is exported, the type annotations must be written in the prototype of the function in the export clause. In that case the type annotation need to be written in the function definition:

(module foo
   (export (succ::int ::int)))

(define (succ x) (+ 1 x))


This Scribe page has been generated by scribeinfo.
Last update Tue Mar 16 17:05:46 2004