gpt4 book ai didi

haskell - 不在范围内 : type constructor or class ‘∼’

转载 作者:行者123 更新时间:2023-12-04 15:56:39 24 4
gpt4 key购买 nike

我正在尝试从 Maguire 的 Thinking with Types 中编译代码片段:

{-# LANGUAGE TypeOperators #-}

data Expr_ a
= (a ∼ Int) => LitInt_ Int
| (a ∼ Bool) => LitBool_ Bool
| (a ∼ Int) => Add_ (Expr_ Int) (Expr_ Int)
| (a ∼ Bool) => Not_ (Expr_ Bool)
| If_ (Expr_ Bool) (Expr_ a) (Expr_ a)

使用 GHCi 8.10.4 版,我得到以下信息:

λ> :l TypeEquality.hs 
[1 of 1] Compiling Main ( TypeEquality.hs, interpreted )

TypeEquality.hs:4:10: error:
Not in scope: type constructor or class ‘∼’
|
4 | = (a ∼ Int) => LitInt_ Int
| ^

TypeEquality.hs:5:10: error:
Not in scope: type constructor or class ‘∼’
|
5 | | (a ∼ Bool) => LitBool_ Bool
| ^

TypeEquality.hs:6:10: error:
Not in scope: type constructor or class ‘∼’
|
6 | | (a ∼ Int) => Add_ (Expr_ Int) (Expr_ Int)
| ^

TypeEquality.hs:7:10: error:
Not in scope: type constructor or class ‘∼’
|
7 | | (a ∼ Bool) => Not_ (Expr_ Bool)
| ^
Failed, no modules loaded.

是否有可以编译的语言编译指示?

最佳答案

真正的问题是我复制并粘贴了书中的代码,而 ~ 符号被格式化为 similar-but-not-identical !我可能不会是最后一个犯这个错误的人,所以希望通过搜索错误消息将有人看到这篇文章。

以下将编译:

{-# LANGUAGE GADTs #-}

data Expr_ a
= (a ~ Int) => LitInt_ Int
| (a ~ Bool) => LitBool_ Bool
| (a ~ Int) => Add_ (Expr_ Int) (Expr_ Int)
| (a ~ Bool) => Not_ (Expr_ Bool)
| If_ (Expr_ Bool) (Expr_ a) (Expr_ a)

关于haskell - 不在范围内 : type constructor or class ‘∼’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69260338/

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