Coder Social home page Coder Social logo

Operators in $if about shakespeare HOT 4 CLOSED

yesodweb avatar yesodweb commented on June 24, 2024
Operators in $if

from shakespeare.

Comments (4)

snoyberg avatar snoyberg commented on June 24, 2024

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
[email protected]
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

from shakespeare.

scan avatar scan commented on June 24, 2024

Is that a general restriction or can that be solved?

from shakespeare.

snoyberg avatar snoyberg commented on June 24, 2024

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.

from shakespeare.

scan avatar scan commented on June 24, 2024

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

from shakespeare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.