gpt4 book ai didi

haskell - Haskell 的 Data.Typeable 是什么?

转载 作者:行者123 更新时间:2023-12-03 05:23:03 25 4
gpt4 key购买 nike

我遇到过对 Haskell 的 Data.Typeable 的引用,但我不清楚为什么要在代码中使用它。

它解决了什么问题以及如何解决?

最佳答案

Data.Typeable 是一种众所周知的方法(参见 Harper)的编码,用于在静态类型语言中实现延迟(动态)类型检查 - 使用通用 类型。

这样的类型包装了类型检查直到稍后阶段才会成功的代码。编译器不会将程序作为错误类型而拒绝,而是将其传递给运行时检查。

这种风格起源于 Abadi 等人,由 Cheney 和 Hinze 为 Haskell 开发,作为表示所有动态类型的包装器,Typeable 类作为 SPJ 和 SYB 工作的一部分出现拉梅尔。

<小时/>

引用

<小时/>

即使在教科书中:动态类型(具有可类型表示)也是只有一种类型的静态类型语言,Harper ch 20:

20.4 Untyped Means Uni-Typed

The untyped λ-calculus may be faithfully embedded in a typed language with recursive types. This means that every untyped λ-term has a representation as a typed expression in such a way that execution of the representation of a λ-term corresponds to execution of the term itself. This embedding is not a matter of writing an interpreter for the λ-calculus in ℒ{+×⇀µ} (which we could surely do), but rather a direct representation of untyped λ-terms as typed expressions in a language with recursive types.

The key observation is that the untyped λ-calculus is really the uni-typed λ-calculus! It is not the absence of types that gives it its power, but rather that it has only one type, namely the recursive type

D = µt.t → t.

关于haskell - Haskell 的 Data.Typeable 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6600380/

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