Giter Site home page Giter Site logo

Unexpected syntax error about bsc HOT 1 OPEN

metanest avatar metanest commented on August 25, 2024
Unexpected syntax error

from bsc.

Comments (1)

quark17 avatar quark17 commented on August 25, 2024

The BH Language Manual mentions the keyword where as used in the package, class, and instance syntax, but does not describe any other usage. I don't know if this omission is intentional or not.

I do see that the BSC parser accepts where in expressions. That is, anywhere that an expression is expected, you can write e where ... -- however, this is only for certain e. Specifically, e has to be a simple expression, like a variable, constructor, tuple, literal, etc, and it can optionally have field selection or bit extraction. It turns out that (e) is considered a tuple of 1 element, so your example can be made to compile by putting the expression in parentheses:

prioEnc i = (f i[2:2] i[1:1] i[0:0])
  where

Of course, you can also use a let-statement instead of where:

prioEnc i =
  let f = ...
  in  f i[2:2] i[1:1] i[0:0]

These two forms are equivalent, because the where is part of the expression, and not part of the declaration of prioEnc.

You could also get it to compile by using a simpler expression preceding the where keyword:

prioEnc i = res
  where
    res = f i[2:2] i[1:1] i[0:0]
    f = ...

I assume that you attempted to use where because you are familiar with Haskell? In Haskell, the where keyword is supported as part of the RHS (right hand side) of a declaration. So in Haskell, the where would be part of the syntax for declaring prioEnc; but that's not what BSC supports.

Where do we go from here? I guess there are four options:

  1. Remove the parser support for expression where so that BSC matches the documentation. (This is probably not what we want to do.)
  2. Leave the BH parser as it is, but document its current behavior in the language manual.
  3. Expand the current where expression syntax, so that it can apply to any expression (not just simple expressions) -- which would allow your example to compile -- and of course document it in the language manual.
  4. Change BSC to support where as a declaration RHS syntax and not as an expression syntax, to match what Haskell supports -- which would also allow your example to compiled -- and of course document it in the language manual.

I'm not sure which is preferable. Maybe @rsnikhil and @mieszko can weigh in.

from bsc.

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.