对于ghc 7.8.3的Singletons 1.0和github master(截至e8a7d6031c)我得到以下错误测试了一些简单的单例示例,这些示例来自Richard Eisenberg的演示文稿以及来自合理近期博客文章的网络github项目(其中一个如下所示):
{-# 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)
|])
所有尝试都会导致相同的错误:
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
我是模板Haskell的新手所以这可能是一个非常明显的错误,但任何人都可以告诉我我做错了什么或者指出了我正确的方向吗?
的ddump-splices输出答案 0 :(得分:2)
从-ddump-splices
输出中可以看到那些不在范围内的名称由forall
限制,然后在函数体中使用。这正是ScopedTypeVariables
扩展的内容。
E.g。以下是t_a4rL
的使用方式:
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) =>
跳过不相关的部分后:
sPlus :: forall (t_a4rL :: Nat_a4rq) ... . ->
sPlus SZero sN
= let lambda_a4rN :: t_a4rL ~ ZeroSym0 ...
添加ScopedTypeVariables
扩展名会将t_a4rL
的范围扩展到sPlus
函数的正文。