With both Singletons 1.0 and github master (as of e8a7d6031c) against ghc 7.8.3 I get the following error testing out some simple singletons examples both from Richard Eisenberg's presentation and around the web from reasonably recent blog posts and github projects (one of them shown below):
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Singletons
import Data.Singletons.TH
main :: IO ()
main = return ()
$(singletons [d|
data Nat = Zero | Succ Nat
plus :: Nat -> Nat -> Nat
plus Zero n = n
plus (Succ m) n = Succ (plus m n)
|])
all attempts result in the same errors:
The exact Name ‘t_a6fM’ is not in scope
Probable cause: you used a unique Template Haskell name (NameU),
perhaps via newName, but did not bind it
If that's it, then -ddump-splices might be useful
The exact Name ‘t_a6fN’ is not in scope
Probable cause: you used a unique Template Haskell name (NameU),
perhaps via newName, but did not bind it
If that's it, then -ddump-splices might be useful
I'm new to Template Haskell so this may be a painfully obvious error, but can anyone tell me what I'm doing wrong or point me in the right direction?
ddump-splices output from ghc: http://lpaste.net/2641476385360576512
From the -ddump-splices output it is possible to see that those not-in-scope-names are bounded by forall and then used in function body. This is exactly what ScopedTypeVariables extension is about.
E.g. here is how t_a4rL is used:
sPlus ::
forall (t_a4rL :: Nat_a4rq) (t_a4rM :: Nat_a4rq).
Sing t_a4rL
-> Sing t_a4rM -> Sing (Apply (Apply PlusSym0 t_a4rL) t_a4rM)
sPlus SZero sN
= let
lambda_a4rN ::
forall n_a4rI. ((ghc-prim:GHC.Types.~) t_a4rL ZeroSym0,
(ghc-prim:GHC.Types.~) t_a4rM n_a4rI) =>
After skipping irrelevant parts:
sPlus :: forall (t_a4rL :: Nat_a4rq) ... . ->
sPlus SZero sN
= let lambda_a4rN :: t_a4rL ~ ZeroSym0 ...
Adding ScopedTypeVariables extension will extend scope of t_a4rL to the body of the sPlus function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With