我正在尝试恢复Symbol
使用的值类型:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Temp where
import GHC.TypeLits
data Temp (d :: Symbol) (a :: *) where
T :: a -> Temp d a
{-
description :: SingI Symbol d => Temp d a -> Sing Symbol d
-}
description (_ :: Temp d a) = (sing :: Sing d)
ghci
这在(版本 7.6.1)中加载良好:
% ghci
GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l Temp
[1 of 1] Compiling Temp ( Temp.hs, interpreted )
Ok, modules loaded: Temp.
*Temp> :t description
description :: SingI Symbol d => Temp d a -> Sing Symbol d
但是,如果我尝试使用ghci
模块本身推断的类型(取消注释 Temp.hs 中的行),我会收到以下错误:
Temp.hs:14:16:
`SingI' is applied to too many type arguments
In the type signature for `description':
description :: SingI Symbol d => Temp d a -> Sing Symbol d
这对我来说很有意义,因为Sing
并且SingI
似乎在文档中采用了一个参数。
什么是正确的类型签名description
?