haskell - Haskell 类型系统的性质 : static/dynamic, 手动/推断?

标签 haskell type-systems typing dynamic-typing static-typing

我正在学习 Haskell,并试图掌握 Haskell 类型系统的工作原理,重新确定事物的类型:动态、静态、手动设置、推断?

我懂一点的语言:

  • C、Java:由程序员手动设置,编译时验证,如int i; , 强类型(从字符串中减去整数是编译错误)。典型的静态类型系统。
  • Python:由运行时自动推断的类型(动态类型),
    强类型(从 int 中减去 str 会引发异常)。
  • Perl,PHP:在运行时自动推断类型(动态类型),弱类型。
  • Haskell:通常在编译时自动推断类型(此类型或类型在编译时由程序员显式设置),强类型。

  • Haskell 的类型系统真的值得描述为“静态的”吗?我的意思是自动类型推断不是(经典)静态类型。

    最佳答案

    Does Haskell's type system really deserve description "static"? I mean automatic type inference is not (classic) static typing.



    类型推断是在编译时完成的。在编译时检查所有类型。 Haskell 实现可以在运行时删除类型,因为它们具有类型安全的编译时证明。

    所以说 Haskell 有一个“静态”类型系统是正确的。 “静态”是指编译时和运行时之间阶段区别的一方面。

    引用罗伯特哈珀的话:

    Most programming languages exhibit a phase distinction between the static and dynamic phases of processing. The static phase consists of parsing and type checking to ensure that the program is well-formed; the dynamic phase consists of execution of well-formed programs. A language is said to be safe exactly when well-formed programs are well behaved when executed.



    来自 Practical Foundations for Programming Languages , 2014 年。

    在这种描述下,Haskell 是一种具有静态类型系统的安全语言。

    作为旁注,我强烈推荐那些有兴趣学习理解编程语言及其特性的基本技能的人看上面的书。

    关于haskell - Haskell 类型系统的性质 : static/dynamic, 手动/推断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26035893/

    相关文章:

    haskell - Monads:确定是否可以进行任意转换

    c++ - 遍历模块中的所有结构

    rust - 为什么在变量上调用方法会阻止 Rust 推断变量的类型?

    PHP 混合类型 vs Typescript any

    typescript - 如何强类型化事件发射器,以便从事件类型推断出处理程序的参数类型?

    class - Haskell 中的实例和类

    haskell - 无法将预期类型 `Int' 与实际类型 [Int] 匹配

    Python 3.5 键入 ABCMeta 未定义 '__getitem__'

    haskell - 比较中的 Monoid 实例在哪里定义?

    haskell - 数字类型签名