我试图恢复值类型中使用的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.h中的行),我会收到以下错误:
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
and SingI
seem to take a single parameter in the documentation。
description
答案 0 :(得分:2)
好的,通过一些关于:
的讨厌description :: SingI d => Temp d a -> Sing d
看起来有一些时髦的重写,但现在还不错。