Hi!
This is my first post. I recently started learning ATS2 and have some trouble grokking what is syntactically correct and what isn't when it comes to the use of braces. Apart from simply understanding the logic of the syntax I would also like to give feedback for future design choices. Let me give some examples. Both of these compile:
val () = if (4 < 5) then
{
val () = println!("true!");
}
else
{
val () = println!("dumb!");
}
and
val () = if (4 < 5) then
begin
println!("true!")
end
else
begin
println!("dumb!")
end
The latter example with alla "begin" and "end" removed also compiles. However, the following version is incorrect:
val () = if (4 < 5) then
{
println!("true!")
}
else
{
println!("dumb!")
}
Why is this? The use of curly braces in function bodies is even more constrained. For example,
fun loop
{ n, i: nat | i <= n }
( n: int n, i: int i, res: int ) : int
= if i >= n then
{
res
}
else loop(n, i+1, (i+1)*res)
does not compile, even with "val"-declarations, but replacing the braces with a "begin ... end" works just fine.
A possibly related question: Why does the "where" keyword only accept braces? E.g, why should
fn fact
( n: Nat ) : int
= loop(n, 0, 1)
where
{
fun loop
{ n, i: nat | i <= n }
( n: int n, i: int i, res: int ) : int
= if i >= n then res
else loop(n, i+1, (i+1)*res)
}
be legit and
fn fact
( n: Nat ) : int
= loop(n, 0, 1)
where
fun loop
{ n, i: nat | i <= n }
( n: int n, i: int i, res: int ) : int
= if i >= n then res
else loop(n, i+1, (i+1)*res)
end
fail? Especially since the "let .. in ..end" requires an "end". I find it difficult to develop a style that I feel is both consistent and pretty. Only using "begin"-"end" looks coherent but requires avoiding "where" (which is a keyword that I am very fond of). To other alternative, to have more keywords than "where" accept braces, would also be preferable, to my mind.
My two main languages are Scala (similar function definitions, "f(x: a): b", but allows using braces as liberally) and Haskell (no need for braces, similar style to doing everything (including where) with "begin"-"end"). Is there a dirty trick to let me code in a style I like, to either have braces as liberally as I currently have "begin"-"end", or, conversely, to have "where"-"end"? The current mash-up annoys me, which is a shame because I love every feature of what my ATS2 code actually *does*. I apologize for being superficial about the looks.
Best wishes,
August