by infradig · 5y ago · 0 comments
let x: i32 = 42;
vs fn fair_dice_roll() -> i32 { 4 }
It seems the designers missed an opportunity, as the latter could quite easily have been: fn fair_dice_roll() : i32 = 4;
or fn fair_dice_roll() : i32 = { ... code that produces 4... }
at the slight expense of giving up the cutesy right-arrow. Maybe i'm just used to Prolog/Lisp code=data syntactic simplicity.And that's as far as I got as I exited the page scratching my head to write this comment.
I personally like the arrow being used for return types as it highlights pretty well what returns stuff. I don't need to track fn definitions or anything when scanning a file - I just need to look for the arrows.
val hello : String = "hello" // eagerly evaluated once
def hello : String = "hello" // evaluated every time
def hello(name: String) : String = s"hello $name" // parameters