singletons
singletons copied to clipboard
singletonization in Nat test is broken when match-flattening
Fix broken singletonization of Nats.
This test looks like this:
$(singletons [d|
data Nat where
Zero :: Nat
Succ :: Nat -> Nat
deriving (Eq, Show, Read)
plus :: Nat -> Nat -> Nat
plus Zero m = m
plus (Succ n) m = Succ (plus n m)
pred :: Nat -> Nat
pred Zero = Zero
pred (Succ n) = n
|])
It fails because for some reason we try to use singletonized data declaration it in the same splice. When this test was originally written we did not use to do that. Why has this changed? Is it because th-desugar is now handling singletonization in a different way?
I fixed the test by making two separate calls to singletons
- one to singletonize data definition and another to singletonize functions. But I'd like to know what's going on here and why is this necessary (ie. I want to be certain that this is not a bug).
I also decided to accept the actual output of the test as the expected one. I looked at the generated output and it seems correct although I admit that after th-desugar switch it's hard for me to comprehend what output should be generated, especially in the case of singletonization.
I'm re-opening this ticket as a reminder that there are some unanswered questions. Once we're certain that none of the above is incorrect we close this ticket.
I'm very confused by this. Singletonization should work with a datatype defined in the same splice, especially with the changes in th-desugar to allow "local" reification. How was it failing before breaking up the splices?
Singletons/Nat.hs:0:0:
Looking up Succ_0123456789 in the list of available declarations failed.
This lookup fails if the declaration referenced was made in the same Template
Haskell splice as the use of the declaration. If this is the case, put
the reference to the declaration in a new splice.
That's a bug. With the new withLocalDeclarations
stuff, this should work just fine.
In that case I'm reverting my earlier patch.
This problem has gone away after reverting match flattening.
Reopening to track the problem within the match-flattening branch.