Scala类型 10 :交集类型(intersection type)与联合类型(union type)
来源:互联网 发布:淘宝游戏交易网 编辑:程序博客网 时间:2024/05/22 08:23
</pre><p>交集类型(<em>intersection type</em>):</p><p>Scala中,复合类型(compound type)既交集类型。表达形式:</p><p><pre name="code" class="java">X with Y with Z...
联合类型(union type):
联合类型的表现形式应该为:
X or Y or Z...
在Scala中没有语法形式的支持union type;但可以通过一些技巧实现。
StackOverflow上有两种实现方式。
- 通过隐式转换(上下文界定):
class StringOrInt[T]object StringOrInt { implicit object IntWitness extends StringOrInt[Int] implicit object StringWitness extends StringOrInt[String]}object Bar { def foo[T: StringOrInt](x: T) = x match { case _: String => println("str") case _: Int => println("int") }}
Scala的类型推断也有其影子,可阅读源码。 - Currying方式:coming soon...
0 0
- Scala类型 10 :交集类型(intersection type)与联合类型(union type)
- scala类型系统:10) 交集类型与联合类型
- Scala 抽象类型Type
- 2.4.2 差别联合类型(discriminated union type)
- Scala 类型: Type vs. Class(类型与类)
- scala类型系统:3) 单例类型与this.type
- Scala类型 8:type 关键字
- enum枚举类型与union联合类型
- Type “”类型“”
- scala 查看对象类型 check type
- Scala入门之高级类型:this.type
- scala进阶14-自身类型self type
- Scala之类型参数化:Type Parameterization
- scala类型系统:8) type关键字
- Scala之类型参数化:Type Parameterization
- wrapped type与primitive type 包装类型与原始类型
- iOS类型编码Type Encodings与属性类型Property Type
- 【Scala类型系统】自身类型(self type)引用
- C语言判断文件夹名是否合法
- shell IFS变量和$*
- MFC学习之路之UI -- (3)信息提示窗口
- c++_primer_exercise_1717_1718
- Android ADB 端口占用问题解决方案
- Scala类型 10 :交集类型(intersection type)与联合类型(union type)
- ubuntu12.04 安装配置jdk1.7
- MFC学习之路之UI --(4)防金山毒霸监控防御的列表框
- MyEclipse逆向生成实体类和Hibernate映射文件
- Transmitting Network Data Using Volley - Sending a Simple Request
- mongodb删除集合后磁盘空间不释放的问题
- (hdu step 5.1.3)Segment set(求与一条线段相交的线段集合中的线段的数量)
- MFC学习之路之UI --(5)美丽的很出名的换肤程序SlickSkins
- fiddler Android下https抓包全攻略