我正在尝试使用GADT和singletons库构建一个正则表达式解析程序。我收到了一条奇怪的错误消息:
Couldn't match type ‘Integer’ with ‘Nat’
Expected type: DemoteRep 'KProxy
Actual type: Nat
In the first argument of ‘toSing’, namely ‘b_a4Vr’
In the expression: toSing b_a4Vr :: SomeSing (KProxy :: KProxy Nat)
我相信我正在使用所有需要的扩展来编译下面的代码:
{-# LANGUAGE DataKinds, KindSignatures,
GADTs, TypeFamilies, TemplateHaskell,
QuasiQuotes, ScopedTypeVariables #-}
module Lib where
import Data.Proxy
import Data.Singletons.Prelude
import Data.Singletons.TH
import Data.Singletons.TypeLits
$(singletons [d|
data RegExp = Sym Nat
| Eps
| Cat RegExp RegExp
| Choice RegExp RegExp|])
type family CHR :: Nat -> Symbol
data InRegExp (e :: RegExp) (n :: Symbol) where
InEps :: InRegExp Eps ""
InChr :: SNat n -> InRegExp (Sym n) (CHR n)
有人可以解释为什么我收到此错误消息?我不知道如何解决它。
答案 0 :(得分:2)
如评论和elaborated on in the singletons
documentation中所述,促销或单例生成不支持支持箭头的数据类型。您应该能够通过推广到data RegExp a = Sym a | ...
来解决这个问题,如评论中所述。
(张贴为无主答案)