koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Koka doesn’t support tabs #516

Closed toastal closed 1 month ago

toastal commented 1 month ago
parse error: invalid syntax
  unexpected tab characters: configure your editor to use spaces instead (soft tab)

I don’t like arguing with coworkers & collaborators over indentation sizing & tabs are configurable compromise as I have visual scanning issue related to 2-space code. Please consider supporting tabs for indentation on the grounds of accessibility.

anfelor commented 1 month ago

Koka uses a whitespace-aware layout algorithm for parsing. This makes it impossible to mix tabs and spaces in a Koka program and Koka traditionally uses spaces. In particular, it would be a lot harder to align Koka code like the third example (eq2) in the linked documentation using tabs. However, if you are interested in writing an autoformatter for Koka that can automatically adjust the spaces in front of a line, I would be happy to advise with that.

toastal commented 1 month ago

Just like programming languages like Haskell, Python, JavaScript, Scala, Go, etc.…

All of these support tabs, & Go pretty much enforces tabs. I’ve never been a fan of bothering to even try to align vertically as it creates a lot of maintenance for when values change (nor does it allow changing the level for a11y). If I were to come into this stylistically blind to current Koka style trends I would have instinctively gone with:

fun eq2(
    x : int,
    y : int
) : io bool
    print(
        "calc "
        ++ "equ"
        ++ "ality"
    )
    val result =
        if (x == y)
            then True
            else False
    result

But if the language is locked to spaces, then it is locked to spaces

TimWhiting commented 1 month ago

I don't think this is an unreasonable request, especially with respect to accessibility, however, I do think that we should have an autoformatter as prerequisite or part of solving this issue. I've opened https://github.com/koka-lang/koka/issues/521 for creating an autoformatter, so let's move further discussion there as far as what sort of configuration should be allowed, and what a 'default' style should look like.