gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:17:28 25 4
gpt4 key购买 nike

我正在尝试恢复值类型中使用的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com