문제

I'm trying to map over an HList in shapeless. The following example is derived from here:

import shapeless._
import poly._

object Main {
    def main(args: Array[String]) = {

        object choose extends (Set ~> Option) {
          def apply[T](s : Set[T]) = s.headOption
        }

        val sets = Set(1) :: Set("foo") :: HNil

        val opts = sets map choose   // map selects cases of choose for each HList element
    }
}

Unfortunately I am unable to compile the example. The compiler says "value map is not a member of HCons[scala.collection.immutable.Set[Int],HCons[scala.collection.immutable.Set[String],HNil]]". I suspect there is a missing import of an implicit that defines the map operation on HLists, but I don't know what that import should be. I'm using sbt with the following build.sbt file:

name := "scala-polymorphism-experiments"

version := "0.1.0"

scalaVersion := "2.10.3"

resolvers ++= Seq(
  "Sonatype OSS Releases"  at "http://oss.sonatype.org/content/repositories/releases/",
  "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
)

libraryDependencies ++= Seq("org.scalatest" % "scalatest_2.10" % "2.0" % "test",
                            "com.chuusai" % "shapeless" % "2.0.0-SNAPSHOT" cross CrossVersion.full changing())

I also have this problem if I use the M1 release of 2.0.0. What should I change to make this example compile and run?

도움이 되었습니까?

해결책

The problem was never determined. The solution was to comment out all code in all other scala files in the project, recompile, then uncomment and compile again. No doubt an

sbt clean

would have done just as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top