Scala Type Syntax

后端 未结 2 672
臣服心动
臣服心动 2020-12-21 01:13

I\'ve observed that, if I want to make a generic function that can accept a list of any type and return a boolean, I can use the following syntax for a function declaration:

2条回答
  •  星月不相逢
    2020-12-21 01:49

    List[_] is an unconstrained existential type and shorthand for List[X] forSome {type X <: Any} (which is like List in Java).

    In this case, I think the function types (not in Scala syntax) forall A. List[A] -> Boolean and (exists A. List[A]) -> Boolean denote the same things, since in both cases you can only inspect the "shape" of the list; probably there's an equivalence between those types.

提交回复
热议问题