This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: type declaration best practices?
- From: Helmut Eller <eller dot helmut at gmail dot com>
- To: kawa at sources dot redhat dot com
- Date: Mon, 11 Jan 2010 09:19:43 +0100
- Subject: Re: type declaration best practices?
- References: <FF51B6B0-46D4-4C37-B521-831014EB4B73@theptrgroup.com> <4AFCA0F9.3060300@bothner.com> <m2my2q3nho.fsf@gmail.com> <4AFD109E.7090307@bothner.com> <4B4AC54C.1020208@bothner.com>
* 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