我发现了一个有趣的语法内容。它叫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]
, 阅读更多 hereThese
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/