gpt4 book ai didi

未评估 Haskell 类型系列应用程序

转载 作者:行者123 更新时间:2023-12-04 04:34:55 26 4
gpt4 key购买 nike

当使用类型族的数据类型时,我发现了一个有趣的情况。

编译器的错误信息是 No instance for (C (ID ())) arising from a use of W .这表明类型族应用程序没有得到充分评估,即使它已经饱和。 :kind! ID ()计算结果为 () ,所以根据 C ()应该使用实例。

{-# LANGUAGE GADTs, TypeFamilies, UndecidableInstances, FlexibleContexts #-}

type family ID t where
ID t = t

class C t where
instance C () where

data W where
W :: C (AppID t) => P t -> W

type family AppID t where
AppID t = (ConstID t) ()

type family ConstID t where
ConstID t = ID

data P t where
P :: P t

data A

w :: W
w = W (P :: P A)

我能否以某种方式强制评估 ID () ?它是编译器错误吗?

我正在使用 GHC 7.8.3

最佳答案

问题是ConstID .

type family ConstID t a where
ConstID t a = ID a

关于未评估 Haskell 类型系列应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25874041/

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