5

我正在尝试恢复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

4

1 回答 1

2

好的,通过一些捣蛋得到了它:

description :: SingI d => Temp d a -> Sing d

看起来有一些时髦的重写正在进行,但现在已经足够了。

于 2012-09-24T16:51:55.560 回答