通过砖墙驱动单例类型 [英] Driving a singleton type through a brickwall

查看:44
本文介绍了通过砖墙驱动单例类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常精简的版本:

Here is a very condensed version:

case class Brickwall[A](otherSide: A)
trait Monoman { def me(m: this.type): Unit }

def test(m: Monoman): Unit = m.me(Brickwall(m).otherSide)

-> error: type mismatch;
 found   : Monoman
 required: m.type

愚蠢的砖墙不让我通过.有什么想法可能吗?秘密的斯卡拉隧道效应?希望...

stupid brickwall doesn't let me through. any ideas how it might be possible? secret scala tunnel effects? hoping...

推荐答案

据我所知 Scala 编译器拒绝推断路径依赖类型,所以一点类型注释有帮助:

As far as I know the Scala compiler refuses to infer path dependent types, so a little type annotation helps:

def test( m: Monoman ) { m.me( Brickwall[m.type]( m ).otherSide )}

这篇关于通过砖墙驱动单例类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆