Closed tomjaguarpaw closed 8 years ago
Actually, plus1 = \(one) x -> add x one
doesn't seem to fix it. Can you tell me what's wrong with this program?
I had to do
partialApply :: Program
partialApply = mconcat
[ Stg.add
, [program|
main = \ => let one = \ -> Int# 1#
in let plus1 = \(one) x -> add x one
in plus1 one
|]]
This seems to be a consequence of "Like letrec, but the bindings cannot refer to each other (or themselves). In other words, let is non-recursive." (from the README). But shouldn't this be enforced at compile time?
Why was this not detected at compile time?
For two reasons,
As for how to write your program, I would use a letrec
.
add = ... -- Prelude
main = \ =>
letrec
one = \ -> Int# 1#;
plus1 = \(one) x -> add x one
in plus1 one
I’ve tried building some better static analysis a couple of times, but it’s not as trivial as I initially thought. I have a long-standing ticket open for reporting unused globals, #23, and a branch that works on that issue (static-analysis
it’s called I believe).
Thanks, I like your letrec
version. Static analysis to detect these errors would be good and will have a look at your branch when I get the time.
Is there anything else I can help you with? Otherwise I’ll close the ticket.
That's fine. You can close this one if you like.
I tried the following program:
It compiled and ran, ending with
I should have written
Why was this not detected at compile time?