27. Bigloo The Programming Language (4.6a) User manual for version 4.6a January 2025 -- Explicit typing

main page
top: | Bigloo The Programming Language (4.6a) User manual for version 4.6a January 2025
Explicit typing
Chapters
| 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. Types are either atomic types (see Atomic types), foreign types (see Defining an extern type), or a classes (see Class declaration). Warning: All type annotations are ignored by the interpreter. Module body type annotations are introduced by the following special forms.
define (f[::type] [a[::type]]...) body | bigloo syntax
define-inline (f[::type] [a[::type]]...) body | bigloo syntax
let ((var[::type] ...) ...) body | bigloo syntax
let loop ((var[::type] ...) ...) body | bigloo syntax
let* ((var[::type] ...) ...) body | bigloo syntax
letrec ((var[::type] ...) ...) body | bigloo syntax
labels ((var[::type] (var[::type]...) b) ...) body | bigloo 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: the basic Scheme types `pair`, `null`, `bstring`, `bint` (presented in Section Defining an extern type). the basic extern types `long`, `int`, `char`, `string` presented in Section Defining an extern type. the compound extern types described in Section Defining an extern type. the types introduced by class declarations (Section Class declaration). 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 Html page has been produced by Skribe.
Last update Mon Jan 27 07:55:49 2025.