在尝试简单的singletons示例时出现模板Haskell错误



使用Singletons 1.0和github master(截至e8a7d6031c)对抗ghc 7.8.3,我从Richard Eisenberg的演示中以及从最近的博客文章和github项目中获得了以下简单的Singletons示例的错误测试(其中一个如下所示):

{-# 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

我是Template Haskell的新手,所以这可能是一个非常明显的错误,但有人能告诉我我做错了什么,或者给我指明正确的方向吗?

ddump拼接来自ghc的输出:http://lpaste.net/2641476385360576512

-ddump-splices输出中可以看到,那些不在作用域名称中的名称由forall限定,然后在函数体中使用。这正是ScopedTypeVariables扩展的意义所在。

例如,以下是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函数的主体。

最新更新