TopLanguage

分享经验是最大的复用!

toplanguageID:TopLanguage
1970次访问,排名2万外好友0人,关注者0
TopLanguage的文章
原创 5 篇
翻译 0 篇
转载 0 篇
评论 0 篇
TopLanguage的公告
除非特别声明,本站采用Creative Commons License许可。注明作者、出处,非商业。

这是一个小组(团体)博客,如果你觉得你的经验值得分享,任何时候欢迎加入我们,请先移步我们的讨论小组TopLanguage

订阅这个博客

  • XML聚合
  • 订阅到鲜果
  • 订阅到Google
  • 订阅到抓虾
  • 订阅到BlogLines
  • 订阅到Yahoo
  • 订阅到GouGou
  • 订阅到飞鸽
  • 订阅到Rojo
  • 订阅到newsgator
  • 订阅到netvibes
最近评论
文章分类
    收藏
      相册
      其他
      TopLanguage人物志
      duguguiyu|Venus神庙
      Googol
      刘未鹏(pongba)|C++的罗浮宫
      刘江|图灵
      孟岩(Mike Meng)
      徐宥(You XU)|4G Spaces&Web 2.3
      杨文博(solrex)|Solrex Shuffling
      莫华枫(longshanksmo)
      袁泳(g9)|负暄琐话
      存档
      软件项目交易
      订阅我的博客
      XML聚合  FeedSky
      订阅到鲜果
      订阅到Google
      订阅到抓虾
      订阅到BlogLines
      订阅到Yahoo
      订阅到GouGou
      订阅到飞鸽
      订阅到Rojo
      订阅到newsgator
      订阅到netvibes

      原创 类型系统的四个维度收藏

      新一篇: API考古学之“C风格的Java API” | 旧一篇: 欢迎加入TopLanguage

       

      By pongba

       

      reddit上看到的。

      这位老大对类型系统作了相当清晰的阐述;到目前为止是我看到的最清晰的。

      其它的要么是盲人摸象(这里这里这里),要么是不着四六(这里),要么是云山雾罩(这里)。

      Latent typing is any type system where you do not need to explicitly write the types of variables down in source code. Its opposite is manifest typing, where you do need to explicitly write the types down in source code.

      Static typing is a type system where individual expressions in the source code must have types, whether written or inferred by the compiler. Dynamic typing is a type system where run-time values have types (or not, as the case may be), yet program expressions can be any type. (Purists often say that dynamic typing isn't a type system at all, since the academic definition of types are a syntactic property of the code, but that's getting overly pedantic IMNSHO.)

      The overlap is in type-inferencing systems. Languages like Haskell and Ocaml are statically-but-latently typed, with the compiler figuring out the types of your variables.

      In theory, there's also an overlap on the other side, where types are written in the source code but aren't checked until runtime. Python 3000 has proposed a system like this, and Common Lisp and Dylan do something similar.

      Bruce Eckel's actually using "latent typing" wrong in this article; he really means "structural subtyping". Basically, structural subtyping means that objects or expressions are tested for type-compatibility based on their structures (the methods/fields/values they support), while "nominal subtyping" means that objects are tested for compatibility based on explicit subtyping declaration by the programmer (think Java interfaces). Haskell, ML, and most dynamically typed languages are structurally-subtyped, while most industrial languages are nominally-subtyped.

      There's also strong vs. weak typing, which has to do with whether the runtime automatically coerces values to different types.

      So basically, there are 4 dimensions:

      • Static (expressions have types) vs. dynamic (values have types)
      • Strong (values cannot be coerced to other types without a cast) vs. weak (the runtime performs a variety of coercions for convenience)
      • Latent (no type declarations) vs. manifest (type declarations)
      • Nominal (subtyping relations are declared explicitly) vs. structural (subtyping relations are inferred from the operations available on types)

      And you can place most languages on one of these 4 axes, though several support multiple forms of typing:

      • Ocaml: static, strong, latent, structural typing
      • Haskell: static, strong, latent, structural typing, with nominal typing available via newtype and manifest typing through optional type declarations.
      • Erlang: dynamic, strong, latent, structural typing
      • Scheme: dynamic, strong, latent, structural typing, with nominal typing available in many object systems.
      • Common Lisp: dynamic, strong, latent or manifest typing. Same note about structural vs. nominal typing as Scheme, but nominal subtyping is used more often in practice.
      • Python & Ruby: dynamic, strong, latent, structural typing. Nominal subtyping is available via isinstance or Ruby equivalent, but good practice frowns upon it.
      • PHP: dynamic, weak, latent, nominal or structural typing. Culture is much friendlier to nominal subtyping than Python or Ruby, but it's not required.
      • Java & C++: mostly static, strong, manifest, nominal typing. The casts give you a form of weak-typing when necessary, and C++ templates are structurally typed.
      • C: static, generally weak, manifest, nominal typing.
      • Assembly: dynamic, weak, latent, structural typing.

      programming: Bruce Eckel: 3-31-04 I'm over it (Java)

      发表于 @ 2007年12月26日 08:36:00|评论(loading...)|编辑

      新一篇: API考古学之“C风格的Java API” | 旧一篇: 欢迎加入TopLanguage

      评论:没有评论。

      发表评论  


      登录
      Csdn Blog version 3.1a
      Copyright © TopLanguage