相关疑难解决方法(0)

Scala 2.8中<:<,<%<和=:=的含义是什么?它们在哪里记录?

我可以在Predef的API文档中看到它们是泛型函数类型(From)=> To的子类,但就是这样.嗯什么?也许某处有文档,但搜索引擎不能很好地处理"<:<"之类的"名称",所以我无法找到它.

后续问题:我什么时候应该使用这些时髦的符号/类,为什么?

scala type-constraints scala-2.8

197
推荐指数
4
解决办法
3万
查看次数

关于implicits的奇怪错误消息

scala> implicit def transitive[A, B, C](implicit f: A => B, g: B => C): A => C = f andThen g
transitive: [A, B, C](implicit f: A => B, implicit g: B => C)A => C

scala> class Foo; class Bar; class Baz { def lol = println("lol") }
defined class Foo
defined class Bar
defined class Baz

scala> implicit def foo2Bar(f: Foo) = new Bar
foo2Bar: (f: Foo)Bar

scala> implicit def bar2Baz(f: Bar) = new Baz
bar2Baz: (f: Bar)Baz …
Run Code Online (Sandbox Code Playgroud)

scala implicit-conversion

6
推荐指数
1
解决办法
300
查看次数

两个看似相同的语义:一个隐式绑定,另一个不绑定

您好:我最近一直在学习Scala(我的相关背景主要是在C++模板中),而且我遇到了一些我目前对Scala不了解的事情,这让我感到疯狂.:(

(另外,这是我在StackOverflow上的第一篇文章,我注意到大多数真正令人敬畏的Scala人似乎都在闲逛,所以如果我对这个机制做了一些非常愚蠢的事情,我真的很抱歉.)

我的具体困惑与隐式参数绑定有关:我提出了一个特定的情况,其中隐式参数拒绝绑定,但具有看似相同的语义的函数确实如此.

现在,它当然可能是一个编译器错误,但鉴于我刚开始使用Scala,我已经遇到某种严重错误的可能性非常小,我期待有人解释我做错了什么.,P

我已经完成了代码并将其削减了很多,以便提出一个不起作用的单个示例.不幸的是,这个例子仍然相当复杂,因为问题似乎只发生在概括中.:(

1)简化的代码不能按我预期的方式工作

import HList.::

trait HApplyOps {
    implicit def runNil
        (input :HNil)
        (context :Object)
        :HNil
    = {
        HNil()
    }

    implicit def runAll[Input <:HList, Output <:HList]
        (input :Int::Input)
        (context :Object)
        (implicit run :Input=>Object=>Output)
        :Int::Output
    = {
        HCons(0, run(input.tail)(context))
    }

    def runAny[Input <:HList, Output <:HList]
        (input :Input)
        (context :Object)
        (implicit run :Input=>Object=>Output)
        :Output
    = {
        run(input)(context)
    }
}

sealed trait HList

final case class HCons[Head, Tail <:HList]
    (head :Head, tail :Tail)
    extends HList
{
    def ::[Value](value :Value) = …
Run Code Online (Sandbox Code Playgroud)

scala implicits

3
推荐指数
1
解决办法
691
查看次数