[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Question about procedure type annotations
From: |
Felix |
Subject: |
Re: [Chicken-users] Question about procedure type annotations |
Date: |
Thu, 25 Oct 2012 04:06:58 -0400 (EDT) |
From: megane <address@hidden>
Subject: [Chicken-users] Question about procedure type annotations
Date: Wed, 24 Oct 2012 18:54:09 +0300
> Hi!
>
> Below is an example that fails.
>
> Is this expected behavior? It feels a bit redundant to use 'assume' for
> the parameter 'a' as the type for the procedure has already been
> declared.
>
> (: foo (fixnum -> undefined))
> (define (foo a)
> (cond-expand
> (compiling
> (compiler-typecase a
> (fixnum #t))
> (else #t)))
> (print a))
>
> ;; Error: in toplevel procedure `foo':
> ;; (test1.scm:2) no clause applies in `compiler-typecase' for expression of
> type `*':
> ;; fixnum
Nothing prevents me from doing
(foo "123")
The procedure can not expect to be always called with correctly typed
arguments, from any possible call-site. The flow-analysis is
intraprocedural and goes not beyond procedure boundaries. You can use
the "-strict-types" option to declare that "foo" will indeed be called
with correctly typed arguments - your example should work with that
option, but calling it with other argument types will result in
undefined behaviour at run-time.
"assume" overrides whatever type-information is available from
flow-analysis (as does "the").
One direction would be to generate type-checks at entry to a
procedure with declared argument types, and I'm currently
working on something related. This would have a run-time cost,
but the arguments would than be known to be correct. I'm
not sure yet what is best.
cheers,
felix