How do I use the trait scala.Proxy

前端 未结 2 1518
心在旅途
心在旅途 2021-01-04 18:37

I just found it in the API and would like to see one or two examples along with an explanation what it is good for.

2条回答
  •  感情败类
    2021-01-04 18:47

    It looks like you'd use it when you need Haskell's newtype like functionality.

    For example, the following Haskell code:

    newtype Natural = MakeNatural Integer
                      deriving (Eq, Show)
    

    may roughly correspond to following Scala code:

    case class Natural(value: Int) extends Proxy {
      def self = value
    }
    

提交回复
热议问题