haskell - 无法对返回 Sing (d::Symbol) 的函数使用 ghci 推断的类型签名

标签 haskell

我正在尝试恢复值类型中使用的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 and SingI seem to take a single parameter in the documentation .

描述的正确类型签名是什么?

最佳答案

好的,通过一些胡闹得到了它:

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

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

关于haskell - 无法对返回 Sing (d::Symbol) 的函数使用 ghci 推断的类型签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569386/

相关文章:

haskell - 数组有 zipWith 函数吗?

parsing - 使用 Parsec 的带引号字符串的解析器

list - 学习 haskell : How to remove an item from a List in Haskell

algorithm - 如何使用折叠实现深树集算法?

haskell - 使用 Sublime 2 进行 Haskell 开发?

php - 使用 PHP 作为 "front end"的 Haskell Web 应用程序

algorithm - 在 Haskell 中将不寻常的序列实现为无限列表

haskell - 在 Haskell 中实现序数

haskell - 允许相等值位于自平衡二叉树两侧的缺点?

haskell - 寻找haskell高阶函数