类型系统的四个维度

本文详细阐述了类型系统中的四个关键维度:静态与动态、强与弱、显式与隐式、名义与结构性子类型,并举例说明了不同编程语言在这四个维度上的定位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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)

### 设计并创建四个维度表的最佳实践 #### 数据仓库中的维度建模原则 在构建数据仓库时,遵循良好的维度建模原则对于确保系统的可维护性和性能至关重要。为了实现这一点,在详细设计之前应为数据仓库系统指定规范,这主要包括源系统、主题、业务术语、报表等方面的规划[^1]。 #### 维度表的选择与定义 当决定要建立哪些维度表时,应当考虑实际业务需求以及未来可能的变化趋势。通常情况下,会选择那些能够描述事实表中记录特征的数据作为维度字段。例如时间戳可以转换成日期维;产品编号对应到商品维等。 #### SQL Server Management Studio (SSMS) 中的具体操作指南 ##### 创建数据库对象前准备 - **确认服务器连接状态正常** - **选择目标数据库** ##### 编写 T-SQL 脚本以创建维度表结构 下面是一个简单的例子来展示如何利用T-SQL语句在一个名为`AdventureWorksDW`的数据库里创建四张典型的维度表格: ```sql USE AdventureWorksDW; GO -- 创建客户维度表 CREATE TABLE DimCustomer ( CustomerKey INT PRIMARY KEY IDENTITY(1,1), FirstName NVARCHAR(50), LastName NVARCHAR(50), EmailAddress NVARCHAR(50), Phone NVARCHAR(25) ); GO -- 创建地理位置维度表 CREATE TABLE DimGeography ( GeographyKey INT PRIMARY KEY IDENTITY(1,1), City NVARCHAR(30), StateProvinceCode CHAR(2), CountryRegionCode VARCHAR(3), PostalCode NVARCHAR(15) ); GO -- 创建产品类别维度表 CREATE TABLE DimProductCategory ( ProductCategoryKey INT PRIMARY KEY IDENTITY(1,1), CategoryName NVARCHAR(50) ); GO -- 创建销售渠道维度表 CREATE TABLE DimSalesChannel ( SalesChannelKey INT PRIMARY KEY IDENTITY(1,1), ChannelDescription NVARCHAR(50) ); GO ``` 上述脚本展示了基本框架下的维度表创建过程,其中包含了必要的约束条件(如主键)。当然,具体的应用场景可能会有所不同,因此还需要根据实际情况调整列名及类型设置。 #### 关于优化建议 考虑到查询效率等因素,在创建索引或者分区策略等方面也需要做出合理安排。比如针对频繁访问的关键字添加非聚集索引可以帮助加速检索速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值