[Prev][Next][Index][Thread]

Re: Dynamic typing confuses me!




"Bertrand Augereau" <baugereau@ifrance.kom> wrote in message
9nbk6l$q8o$1@wanadoo.fr">news:9nbk6l$q8o$1@wanadoo.fr...
> Hello, I'm coming from a traditional strongly-typed background (C++ &
Ada95)
> and I'm trying to get a grasp on modern functional objects.
> Why does this code give a run-time error?
>
> define method fact (x) => ()
> if (x = 1)
>   1;
> else
>   fact(x - 1) * x;          <<<<<
> end;
> end method fact;

It gives you a run-time error because you have declared
the function 'fact' to return no values.   The indicated line
will crap out multiplying #f by x, which will die.

The compiler really should have given you a compile-time
error for this.  Any Fun-O compiler hackers should construe
this as a bug report.

> define method main () => ()
> fact (5);
> end method main;
>
> begin
>   main();
> end;
>
>
> ...if I give it all the typing info, it works but it seems to me it can
> infer it in theory.
> Am I completly misunderstanding?
>
> BTW I'm using functional developer...
>

Tight mode or loose mode?  Loose mode gives poorer type
warnings as compile-time.





References: