Please enable newer versions of Node for the JavaScript version of this kata, as it is in Simpler Interactive Interpreter. Coming from there and then having to rewrite larger parts of the existing code, because one used features that are not available in Node 8, is an unnecessary obstacle.
No it is not. The production rule for function call is given as
function-call ::= fn-name { expression }
That says, that the arguments of the call are expressions. 3 + 4 is an expression, so interpreting the input f 2 3 + 4 as equivalent to f 2 (3 + 4) is valid according to the grammar. That the grammar lists function-call (only) as an option for factor does not change that. The grammar is simply ambiguous. In more ways than this.
I think that error message is a result of UndecidableInstances masking the real problem. Without that option, GHC throws an error, that it can not see, that the functional dependency t → r is satisfied in the second instance:
• Illegal instance declaration for ‘Variadic a r (a' -> t)’
The coverage condition fails in class ‘Variadic’
for functional dependency: ‘t -> r’
Reason: lhs type ‘a' -> t’ does not determine rhs type ‘r’
Un-determined variable: r
Using UndecidableInstances might help
• In the instance declaration for ‘Variadic a r (a' -> t)’
|
13 | instance (a ~ a', Variadic a r t) => Variadic a r (a' -> t) where
|
Removing the functional dependency resolves that, but then GHC complains about an ambiguous type in polyList.
I have no idea how to resolve that. I have been banging my head against the wall for a whole day trying to get a similar solution working, before settling for a less elegant solution.
I really like the use of the Void type in coerce here. Really drives home the fact that the inner value can not actually exist and the whole thing is, well, absurd.
While this solution is simple and looks nice, it is not portable because of a byte order problem.
On a machine with big-endian byte order, this formats the IP the wrong way around.
It's a shame, much software out there is not really portable because of little assumptions like that.
Please enable newer versions of Node for the JavaScript version of this kata, as it is in Simpler Interactive Interpreter. Coming from there and then having to rewrite larger parts of the existing code, because one used features that are not available in Node 8, is an unnecessary obstacle.
No it is not. The production rule for function call is given as
That says, that the arguments of the call are
expression
s.3 + 4
is an expression, so interpreting the inputf 2 3 + 4
as equivalent tof 2 (3 + 4)
is valid according to the grammar. That the grammar listsfunction-call
(only) as an option forfactor
does not change that. The grammar is simply ambiguous. In more ways than this.I think that error message is a result of
UndecidableInstances
masking the real problem. Without that option, GHC throws an error, that it can not see, that the functional dependencyt → r
is satisfied in the second instance:Removing the functional dependency resolves that, but then GHC complains about an ambiguous type in
polyList
.I have no idea how to resolve that. I have been banging my head against the wall for a whole day trying to get a similar solution working, before settling for a less elegant solution.
All in all nice, but there is a much simpler definition for
false
, that also only relies on the primitive combinators.I really like the use of the
Void
type incoerce
here. Really drives home the fact that the inner value can not actually exist and the whole thing is, well, absurd.While this solution is simple and looks nice, it is not portable because of a byte order problem.
On a machine with big-endian byte order, this formats the IP the wrong way around.
It's a shame, much software out there is not really portable because of little assumptions like that.
Hmm, I don't think this qualifies as "[...] contains code within it that might give the solution away to other users."
But thanks anyway. I will remember to do it next time :)
Please use spoiler flag.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution