Confusion about type refinement syntax

后端 未结 1 1025
忘了有多久
忘了有多久 2021-01-23 12:37

On Type Level, i stumble upon the following:

sealed abstract class StSource[A] {
  type S
  def init: S            // create the initial state
  def emit(s: S): (         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 12:53

    StSource[A] {type S = S0} is a refined type. {type S = S0} is a type refinement.

    From one side, StSource[A] {type S = S0} is a subtype of StSource[A].

    From the other side, StSource[A] is also an existential type with respect to StSource[A] {type S = S0}, namely StSource[A] is StSource.Aux[A, _] (aka StSource.Aux[A, X] forSome {type X}).

    def test[A, S] = {
      implicitly[StSource.Aux[A, S] <:< StSource[A]]
      implicitly[StSource.Aux[A, _] =:= StSource[A]]
      implicitly[StSource[A] =:= StSource.Aux[A, _]]
    }
    

    https://scala-lang.org/files/archive/spec/2.13/03-types.html#compound-types

    A compound type

    0 讨论(0)
提交回复
热议问题