Idris-dev icon indicating copy to clipboard operation
Idris-dev copied to clipboard

Using syntax rules should require fewer parentheses

Open mietek opened this issue 10 years ago • 5 comments

Syntax rules using symbols as separators require more parentheses than syntax rules using keywords as separators. Tested with Idris 0.9.19.

module SyntaxProblem

helper : () -> () -> ()
helper _ _ = ()

syntax rule [a] keyword [b] = helper a b
syntax brokenRule [a] "+++" [b] = helper a b

example : ()
example = rule helper () () keyword helper () ()

brokenExample : ()
brokenExample = brokenRule helper () () +++ helper () ()
./SyntaxProblem.idr:13:17: error: unexpected
    reserved
    identifier, expected: dependent type signature
brokenExample = brokenRule helper () () +++ helper () ()
                ^

Adding more parentheses helps, but partially defeats the purpose of using syntax rules.

brokenExampleWorkaround : ()
brokenExampleWorkaround = brokenRule (helper () ()) +++ helper () ()

Related to #2566 and #2567 by way of error message.

mietek avatar Sep 06 '15 23:09 mietek

I unfortunately wouldn't expected that this gets fixed, but I will still tag it if someone else wants to look at this. It is inherently a hard problem to give good error messages with so expressive syntax extensions.

ahmadsalim avatar May 15 '16 11:05 ahmadsalim

Note that my complaint is primarily about the behaviour of the parser, and not the error message.

mietek avatar May 15 '16 12:05 mietek

Related example:

typeApply : (a : Type) -> (a -> b) -> (a -> b) -- does work
typeApply _ f = f

infixl 10 @@
syntax [f] "@@" [a] = typeApply a f

t : String -> Int
-- t = id . const 3 @@ String -- broken
t = (id . const 3) @@ String -- works

On top of that the error message is really confusing:

Type checking ./TypeApplication.idr
TypeApplication.idr:8:3:When checking right hand side of t with expected type
        String -> Int

When checking an application of function Prelude.Basics..:
        No such variable @@

gallais avatar Jun 19 '17 12:06 gallais

@gallais Your issue seems particularly weird, since "@@" is not a legal variable.

I unfortunately still do not have any idea how to improve syntax extensions in Idris in a usable and backwards compatible fashion. Ideas are welcome on how to solve the issue.

ahmadsalim avatar Jun 19 '17 12:06 ahmadsalim

I don't know much about these things but I suspect that short of implementing a full parser for arbitrary mixfix expressions à la Agda, it'll always fall short of advanced users' expectations?

gallais avatar Jun 19 '17 14:06 gallais