What is a good reason to use a type signature for functions when the compiler can infer the types

后端 未结 4 598
梦谈多话
梦谈多话 2021-01-17 09:44

I am trying to code using \'good Haskell style\' and so am trying to follow typical coding standards I find around. Also, compiling with -Wall and -Werror as I am used to w

4条回答
  •  无人共我
    2021-01-17 10:19

    I would consider documentation one advantage of having an explicit type signature.

    From "Types and Programming Languages":

    Types are also useful when reading programs. The type declarations in procedure headers and module interfaces constitute a form of documentation, giving useful hints about behavior. Moreover, unlike descriptions embedded in comments, this form of documentation cannot become outdated, since it is checked during every run of the compiler. This role of types is particularly important in module signatures.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题