[Types-sig] type declaration syntax

skaller skaller@maxtal.com.au
Sat, 18 Dec 1999 15:08:14 +1100

On syntax: for functions, the use of ":" for parameters 
seems 'natural' to me:

	def f(a:Int, y:Float=0.0)

as it is used in pascal and ML. But the return type
is a problem. Suggestions include

	def f() -> Float


	def f: Float ()

and I'll add using -> in the list:

	def f(a->Int, y->Float)-> Float: ..

but here is another idea: don't bother.

The reason is: local type inference needs to know
the parameter types, and these are needed for call

But the _return_ type doesn't need to be annotated as much.
Why? Because the inferencer can usually deduce it:
it's an output, the argument types are inputs.

If the inferencer _cannot_ deduce the return type,
it _also_ cannot check that the function is returning
the correct type.

It is true that knowing the return type can help
inferencing, and it is true it is needed for inferencing
at the point of call, although in this case the deduced
type is (may be) still available.

Only an idea .. but "when in doubt, don't", is a good rule
for language design :-)

One problem with :, that is probably a killer: it cannot
work with lambdas:

	lambda x:Int, y: woops

[I'm not saying if this will kill ":" or lambda though  :-]

John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850