Open metanest opened 3 months ago
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:
where
so that BSC matches the documentation. (This is probably not what we want to do.)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.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.
This BlueSpec Classic code ...
result is following unexpected syntax error