singletons icon indicating copy to clipboard operation
singletons copied to clipboard

singletonization in Nat test is broken when match-flattening

Open jstolarek opened this issue 10 years ago • 7 comments

Fix broken singletonization of Nats.

jstolarek avatar Sep 26 '14 06:09 jstolarek

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.

jstolarek avatar Apr 09 '15 09:04 jstolarek

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?

goldfirere avatar Apr 09 '15 16:04 goldfirere

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.

jstolarek avatar Apr 09 '15 16:04 jstolarek

That's a bug. With the new withLocalDeclarations stuff, this should work just fine.

goldfirere avatar Apr 09 '15 16:04 goldfirere

In that case I'm reverting my earlier patch.

jstolarek avatar Apr 09 '15 16:04 jstolarek

This problem has gone away after reverting match flattening.

jstolarek avatar Apr 19 '15 08:04 jstolarek

Reopening to track the problem within the match-flattening branch.

goldfirere avatar Apr 19 '15 23:04 goldfirere