Haskell中数据种类和单例的问题

时间:2016-04-14 13:46:14

标签: haskell dependent-type singleton-type

我正在尝试使用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) 

有人可以解释为什么我收到此错误消息?我不知道如何解决它。

1 个答案:

答案 0 :(得分:2)

如评论和elaborated on in the singletons documentation中所述,促销或单例生成不支持支持箭头的数据类型。您应该能够通过推广到data RegExp a = Sym a | ...来解决这个问题,如评论中所述。

(张贴为无主答案)