Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operators in $if #13

Closed
scan opened this issue Mar 15, 2011 · 4 comments
Closed

Operators in $if #13

scan opened this issue Mar 15, 2011 · 4 comments

Comments

@scan
Copy link

scan commented Mar 15, 2011

Another issue I have found, not documented, is using an operator in an $if, like so:

$if (length list) > 2
$if isValid (a+b)

And other examples (with ==) and such... they all produce the error 'Unexpected >' or 'Unexpected =' and so on. Is that intended? If I define a function

let eq = (==)

It works fine, and operators are just functions, so shouldn't that work?

Addition:

$if (length list) `eq` 1

yields the same problem.

@snoyberg
Copy link
Member

No, you can't use an operator like that, that's why it's not
documented ;). Doing so would require knowing all of the precedence
levels, which is not available to the TH code involved. You can
instead do something like this:

$if (>) (length list) 2
$if isValid $ (+) a b

On Tue, Mar 15, 2011 at 8:36 PM, scan
reply@reply.github.com
wrote:

Another issue I have found, not documented, is using an operator in an $if, like so:

   $if (length list) > 2
   $if isValid (a+b)

And other examples (with ==) and such... they all produce the error 'Unexpected >' or 'Unexpected =' and so on. Is that intended? If I define a function

   let eq = (==)

It works fine, and operators are just functions, so shouldn't that work?

Reply to this email directly or view it on GitHub:
https://github.com/snoyberg/hamlet/issues/13

@scan
Copy link
Author

scan commented Mar 15, 2011

Is that a general restriction or can that be solved?

@snoyberg
Copy link
Member

I don't think it's solvable, but more to the point, I don't want to solve it. I think allowing arbitrary infix syntax is a bad direction for Hamlet. I agree 100% that it would be useful in many situations, but it also leads to some ambiguity. For example, the same Hamlet template could have different meanings depending on which modules are in scope when it is called.

On the other hand, we could simply force all operators to have the same precedence rules, but then it won't line up with the Haskell code.

@scan
Copy link
Author

scan commented Mar 15, 2011

Yes, ok, thanks. It makes sense there, after all, it makes no difference for the program, only to the programmer.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants