Open showell opened 4 years ago
The original issue involved this code inside a let
statement:
parseExpr : Parser Expr
parseExpr =
oneOf
[ value
, Parser.lazy (\_ -> list parseExpr)
]
(I recommend debugging it with the factorial examples in the OP, though. Just providing this for context--I wasn't doing anything crazy.)
So the original motivation for this bug report was I using
Parser
to parse something akin to JSON. Getting a minimal repro on that was difficult, so let's go to our old friend "factorial".The below code works fine (the key thing to note is that
f
is inside thelet
):And this code works fine:
This nearly identical code won't compile:
The error is below. It's misleading, because
func
is defined indirectly in terms of itself.func
doesn't directly call itself--it uses a lambda. The error message should somehow suggest that recursive functions must be top-level (but it's more subtle than that--something about puttingfunc
in the record there is causing the error).