Comments (5)
I think it's related to the way jupyter-scala "wraps" the user code, in classes rather than in singletons (this allows for Java serialization to work properly, e.g. for Spark). I ran into similar issues with shapeless, like
@ load.ivy("com.chuusai" %% "shapeless" % "2.2.0-RC6")
...
res0: Unit = ()
@ trait Defs {
sealed trait Base
case class Bar(i: Int) extends Base
case class Baz(s: String) extends Base
}
defined trait Defs
@ object Defs extends Defs
defined object Defs
@ import shapeless._
import shapeless._
@ Generic[Defs.Bar].to(Defs.Bar(2))
res4: shapeless.::[Int,shapeless.HNil] = ::(2, HNil)
@ Generic[Defs.Base].to(Defs.Bar(2))
Compilation Failed
Main.scala:58: could not find implicit value for parameter gen: shapeless.Generic[cmd5.this.$ref$cmd2.Defs.Base]
Generic[Defs.Base].to(Defs.Bar(2))
^
@ Generic.materialize[Defs.Base, Defs.Bar :+: Defs.Baz :+: CNil].to(Defs.Bar(2)) // Explicit type parameters
Compilation Failed
Main.scala:62: pattern type is incompatible with expected type;
found : Defs.this.Bar
required: cmd11.this.$ref$cmd2.Defs.Base
Generic.materialize[Defs.Base, Defs.Bar :+: Defs.Baz :+: CNil].to(Defs.Bar(2))
^
(ran with https://github.com/alexarchambault/ammonite-shell on which jupyter-scala is based, not Ammonite main line).
I'm not excluding the problem is on the side of the underlying macros (those of shapeless or rapture). Definitely something that has to be disentangled.
from almond.
This definitely looks like a rapture issue, see this session with "standard" wrappers (with your example being ok, as in Ammonite main line):
Loading Ammonite Shell...
@ load.ivy("com.propensive" %% "rapture-core" % "1.1.0"); load.ivy("com.propensive" %% "rapture-json-jackson" % "1.1.0")
...
res0_0: Unit = ()
res0_1: Unit = ()
@ import rapture.json.jsonBackends.jackson._; import rapture.json._; import rapture.core._; import modes.returnTry; import formatters.humanReadable._
import rapture.json.jsonBackends.jackson._
import rapture.json._
import rapture.core._
import modes.returnTry
import formatters.humanReadable._
@ // Your example runs fine
@ case class Dog(name: String, age: Int)
defined class Dog0
@ case class DogOwner(dog: Dog, name: String)
defined class DogOwner0
@ val d = Dog("Tyler", 15); val q = DogOwner(d, "Frank"); d.age
d: cmd2.Dog = Dog("Tyler", 15)
q: cmd3.DogOwner = DogOwner(Dog("Tyler", 15), "Frank")
res4_2: Int = 15
@ val dogJS = Json(d).toString; val aDog = Json.parse(dogJS).as[Dog]
dogJS: java.lang.String = """
{"name":"Tyler","age":15}
"""
aDog: cmd2.Dog = Dog("Tyler", 15)
@ // Now with a very simple type parameter
@ case class Dog1[T](name: String, age: T)
defined class Dog1
@ case class DogOwner1(dog: Dog1[Int], name: String)
defined class DogOwner1
@ val d1 = Dog1("Tyler", 15); val q1 = DogOwner1(d1, "Frank"); d1.age
d1: cmd6.Dog1[Int] = Dog1("Tyler", 15)
q1: cmd7.DogOwner1 = DogOwner1(Dog1("Tyler", 15), "Frank")
res8_2: Int = 15
@ val dogJS1 = Json(d1).toString; val aDog1 = Json.parse(dogJS1).as[Dog1]
Compilation Failed
Main.scala:36: Cannot serialize type cmd6.Dog1[Int] to rapture.json.Json. Please provide an implicit Serializer of type cmd6.Dog1[Int].
val dogJS1 = Json(d1).toString ; val aDog1 = Json.parse(dogJS1).as[Dog1]
^
When inspecting case classes, I'd say @propensive should call some asSeenFrom
on the types of the members of the case class. Should be something similar for shapeless in my previous comment.
So there's definitely a problem on the rapture side, I let you report this to it if you'd like. I'll have a look at shapeless, and close this issue if I know for sure nothing wrong is done on the jupyter-scala side.
from almond.
Cool. Thanks for looking into this. I'll pass this along to @propensive.
from almond.
Is there a work around to this (i.e. getting a type declared outside the wrappers)?
from almond.
In the develop
branch (soon to be the default), one can just explicitly wrap definitions in object Something { … }
for them not to be later put inside a class definition. That should appease faulty macros like here.
from almond.
Related Issues (20)
- Lots of output messages cause kernel to stuck HOT 1
- Create NotebookSparkSession error on windows HOT 4
- Create NotebookSparkSession on windows error Failed to connect to timeline server
- Add section in docs about custom Toree magics
- Almond on windows is not use spark config in spark-default and hadoop config in hadoop config dir
- Docker ivy command stalls with a mounted volume
- named imports cannot follow wildcard imports HOT 1
- Scala 2.13.8 Almond 0.13.14 issue
- version compatibility with almond-sh on windows when use spark HOT 1
- Almond 0.13.2: InterpreterToIOInterpreter Error for Scala mixin type parameter constraint HOT 1
- Could not find or load main class coursier.bootstrap.launcher.Launcher HOT 2
- Installing the Scala kernel in standalone mode can execute code 5X slower than normal mode!! HOT 1
- Getting sbt-coursier error when upgrading from sbt version 1.3.13 to 1.9.4
- Spark 3.1.2 failing to create SparkSession in Almond 0.14.0-RC12 HOT 1
- Pre-fetching jars in docker environment fails to populate classpath HOT 4
- Reexecuting a Scala 3.3.1 cell with circe imports fails with `an identifier expected, but 'export' found` HOT 4
- Failed to import spark HOT 3
- Installed version is not aligned with dependencies
- Recent versions of Spark not supported ? (ClassCastException error) HOT 1
- Specified to use Scala 3 but Scala 2 still being used HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from almond.