futhark icon indicating copy to clipboard operation
futhark copied to clipboard

Allowing omission of 'let' before 'loop', 'if', and 'match'

Open athas opened this issue 1 year ago • 4 comments

For a long time we've supported not having to put in when chaining let:

let foo = ...
let bar = ...
let baz = ...
in ...

Sometimes the expression following in is a loop, if, or match. In those cases, we could also make the in itself optional. Then we could write things like

  def build_table (rng: E.rng) =
    let xs = replicate k (int.i32 0)
    loop (rng,xs) for i < K.k do
      let (rng,x) = E.rand rng
      in (rng, xs with [i] = x)

or

let examinationPoint = lowerLimit + ( (upperLimit - lowerLimit) / 2 )
if A[examinationPoint] > quarry
then (lowerLimit, examinationPoint)
else (examinationPoint, upperLimit)

It's a pretty simple change to the grammar and completely unambiguous. But is it something we want?

athas avatar Aug 02 '22 12:08 athas

Hm, I'm not sure I like the aesthetics of this. Of course, you'll save writing a keyword here and there, but I don't feel like there's any real benefit to it.

Munksgaard avatar Aug 02 '22 12:08 Munksgaard

I think the main advantage (if any) is less indentation.

athas avatar Aug 02 '22 12:08 athas

Do we have many programs that are so deeply indented that this will cause a significant difference?

Munksgaard avatar Aug 02 '22 13:08 Munksgaard

No, but it sometimes causes a small difference.

athas avatar Aug 02 '22 13:08 athas

I personally would even think it's more confusing as a programmer learning Futhark. I'd rather see it being consistent and having the in everywhere. But that's just me. I'm not a language theorist. I just use Futhark :p

rowanG077 avatar Sep 09 '22 12:09 rowanG077

Alright, let's not do this.

athas avatar Sep 09 '22 19:09 athas