At 10:48 am -0300 20/5/99, Carlos Camarao de Figueiredo wrote:
> investigate (it seems a little strange to provide type inference and
> also require top-level type declarations).
Well I might disagree - I'm one of those who think type declarations help to document
the code, though I'm happy to omit them from local definitions - but it is an unusual
mix. In Hope+C history is the reason:
Hope, the predecessor to Hope+ (say it :-)) - which became Hope+C during
implementation had top-level type declarations but not local ones. For example:
dec f : char -> int;
--- f(x) <= let g = lambda z =>ord(z)
in g(x);
g did not require, and indeed could not have, a type declaration; f did require one.
Obviously to type g requires inference, though localised.
When we undertook the Hope+C project I wrote the type "checker" to support general
inference - in the above syntax the top-level type declaration is used to tie down
types a bit quicker (and in the context of overloading, if multiple ones exist they
are all considered at the same time).
Later versions of Hope+C provided the sytnax:
let f : char -> int
== fun x -> let g == fun z -> ord (z) end
in g(x)
end;
The compiler infers the type of the function and then compares it to the declared
type, if it exists, and this of course may remove some variables. The type is not
required by the type "checker", but I don't think the parser was ever altered to allow
users to omit it! Similarly I allowed for adding local type declarations, but the
parser was never altered to allow them - the Hope+C compiler was a team production
produced to deadlines and extra bits only got in if individuals found time.
In the context of the original context, ad-hoc overloading, type declarations not only
help to document the program but also help the inferer tie down alternatives quicker.
Cheers,
Nigel
--
Nigel Perry, New Zealand. It makes as much sense to wear a "cycle style" helmet in a
car as on a bike... Choosing to wear one on a bike but not in a car is mere
inconsistency. Refusing to wear one in a car while insisting others do so on a bike is
pure hypocrisy. Don't be a hypocrite.