This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: type declaration best practices?


* Per Bothner [2010-01-11 07:29+0100] writes:

> Given that we're more-or-less stuck with :: what would be
> the preferred type declaration syntax?  For variable declarations
> I think I would recommend keeping the space before the colon,
> but leaving it out after, as in:
>
> (define var1 ::int 10)
> (let ((var2 ::list (cons x y))) ...)
>
> For function declarations, I'm dithering between:
> (1)
> (define (string-ref (str ::string) (k ::int)) ::char
>   (invoke str 'charAt k))
> (2)
> (define (string-ref str ::string k ::int) ::char
>   (invoke string 'charAt k))
> (3)
> (define (string-ref str::string k::int) ::char
>   (invoke string 'charAt k))
>
> (1) is more verbose, but it may be easier to read (for
> humans) and it handles default values (for #!optional
> parameters) better.
>
> Comments?

In (1) the colons seem redundant except for the return type.  

> So how would (future) type annotations fit in?  I think by
> coming after the :: as in:
> (define x ::(@NonNull)string (...))

Keywords could also be used like:

(define x :: string annotation: NonNull value)
or perhaps
(define x (string annotation: NonNull) value)

There could be a rule that if define has 3 arguments the second are
annotations.  And as shortcut, if the second argument is a symbol it's a
type:

(define x int 10) 

would be the same as now (define x :: int 10)

Helmut


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]