我尝试用标记类型从scalaz加强型安全。
我遇到了一个警告,并且我不明白的错误。
你能解释一下我两者兼而有之?
这里是控制台输出:
scala> sealed trait PostId
defined trait PostId
scala> def PostId(l: Long) : Long @@ PostId = Tag[Long, PostId](l)
PostId: (l: Long)scalaz.@@[Long,PostId]
warning: previously defined trait PostId is not a companion to method PostId.
Companions must be defined together; you may wish to use :paste mode for this.
scala> case class Post(id: PostId)
defined class Post
scala> Post(PostId(2l))
<console>:26: error: type mismatch;
found : scalaz.@@[Long,PostId]
(which expands to) Long with AnyRef{type Tag = PostId}
required: PostId
Post(PostId(2l))