GithubHelp home page GithubHelp logo

Comments (5)

alexarchambault avatar alexarchambault commented on July 21, 2024

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.

alexarchambault avatar alexarchambault commented on July 21, 2024

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.

tylerprete avatar tylerprete commented on July 21, 2024

Cool. Thanks for looking into this. I'll pass this along to @propensive.

from almond.

metasim avatar metasim commented on July 21, 2024

Is there a work around to this (i.e. getting a type declared outside the wrappers)?

from almond.

alexarchambault avatar alexarchambault commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.