scala - Scala 中缀类型的真实例子

标签 scala

我发现了一个有趣的语法内容。它叫Infix type .

例子:

class M[T, U]
new (Int M String)

现在我正在从一些流行的框架或库中寻找这种类型的示例。我在哪里可以找到它们?有什么建议?

最佳答案

shapeless library

有一堆

Polymorphic functions

Set ~> Option

很像
Set[A] => Option[A] forAny {type A}

HLists
Int :: String :: Double :: HNil 

就像一个 super 灵活的版本
(Int, (String, (Double, ())))

Coproducts
Int :+: String :+: Double :+: CNil

就像是 super 灵活的版本
Either[Int, Either[String, Either[Double, Nothing]]]

Type tags
Int @@ NonNegative

Int 的零成本运行时模拟在标签类型中记住一些信息

scalaz library

正如 Archeg 提到的那样,它们甚至更多

Either
String \/ Long

是 Scala 的更酷版本 Either[String,Long] , 阅读更多 here

These
Boolean \&/ Long

是方便的实现
Either[(Boolean, Long), Either[Boolean, Long]]

Map
String ==>> Double

是haskellest版本
collection.immutable.TreeMap[String, Double]

Monoid Coproduct
String :+: Float

是事物的交替列表,其中聚合相似的事物(添加、连接、选择最大值等)而不是排序

关于scala - Scala 中缀类型的真实例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33347955/

相关文章:

oop - 如何处理特定类型集合的操作?

scala - 为什么向左折叠期望(a -> b -> a)而不是(b -> a -> a)?

scala - 在 Scala 中,将顶级特征声明为私有(private)或包私有(private)有什么区别?

scala - 如何避免 'Non-variable type argument is unchecked since it is eliminated by erasure' ?

java - 如何使用 Java EWS API 搜索 iCalUid 的 Exchange 约会?

scala - 如何在spark中将单个RDD划分为多个RDD

mysql - 使用 Slick 3.0 连接到 Mysql - No username, no password and bogus driver does not equal error

algorithm - 如何在 Scala 中简化表达式(and、or、not)?

scala - SBT 从使用 xsbt-web-plugin 打包的 war 文件中排除 scala-library.jar

scala - specs2 -- 无法创建实例