« Return to Thread: Another formatting question: function types

Re: Another formatting question: function types

by Daniel Spiewak :: Rate this Message:

Reply to Author | View in Thread

1. Without spaces
2. Without parens

For example:

String=>Unit
(String, Int)=>Unit

I think this makes it a little cleaner without taking up too much space.  Also, I think it makes type annotations a bit easier to read.  For example:

val foo: String=>Unit = ...

vs.

val foo: String => Unit = ...

The extra spaces require a little more effort to parse (at least to my eye).  Rather than relying on spacing to delineate value, type and expression, I have to actually look at "=>" vs "=", symbols which have comparatively little visual distinction.

As a matter of interest, when programming Haskell or SML, I do prefer the spaces syntax:

-- Haskell
foldl :: (b -> a -> b) -> b -> List a -> b

(* SML *)
fun foldl f : (('b, 'a) -> 'b) init : 'b ls : ('a list) = ...

I'm not quite sure why I find the spaces better in Haskell/SML and not in Scala, but there it is.

Daniel

Bill Venners-3 wrote:
Hi All,

I wanted to take the community's temperature on how they prefer to see
function types formatted. I have three questions.

1. Do you want spaces around the => or not? Here is with spaces:

(String, Int) => Unit

Here is without:

(String, Int)=>Unit

2. If a type has arity 1, do you want parens around it or not? Here it
is with parens:

(String) => Unit

Here it is without:

String => Unit

3. Lastly, anything else you like to see?

Thanks.

Bill
----
Bill Venners
Artima, Inc.
http://www.artima.com

 « Return to Thread: Another formatting question: function types