softwaremill / magnolia

Easy, fast, transparent generic derivation of typeclass instances
https://softwaremill.com/open-source/
Apache License 2.0
760 stars 116 forks source link

Example with `default` doesn't compile for me #144

Open anne-decusatis opened 5 years ago

anne-decusatis commented 5 years ago

I was trying to make a small change to the default example, and wanted to test that my change didn't break anything. The compilation error I see looks like it's an issue between Mercator and Either, my guess is because Either has two type parameters (for Left and Right) and Monad only has one (equivalent to Right), but I don't know enough to submit a PR to fix. Please let me know if there's any more information I can provide!

sbt:root> test
[info] Compiling 9 Scala sources to /home/anned/github/magnolia/examples/native/target/scala-2.11/classes ...
[error] /home/anned/github/magnolia/examples/shared/src/main/scala/default.scala:31:23: no type parameters for method constructMonadic: (makeParam: magnolia.Param[magnolia.examples.Default,T] => Monad[PType])(implicit monadic: mercator.Monadic[Monad])Monad[T] exist so that it can be applied to arguments (magnolia.Param[magnolia.examples.Default,T] => scala.util.Either[String,magnolia.Param[magnolia.examples.Default,T]#PType])
[error]  --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error]  found   : magnolia.Param[magnolia.examples.Default,T] => scala.util.Either[String,magnolia.Param[magnolia.examples.Default,T]#PType]
[error]  required: magnolia.Param[magnolia.examples.Default,T] => ?Monad[?PType]
[error]     def default = ctx.constructMonadic { param =>
[error]                       ^
[error] /home/anned/github/magnolia/examples/shared/src/main/scala/default.scala:31:48: type mismatch;
[error]  found   : magnolia.Param[magnolia.examples.Default,T] => scala.util.Either[String,magnolia.Param[magnolia.examples.Default,T]#PType]
[error]  required: magnolia.Param[magnolia.examples.Default,T] => Monad[PType]
[error]     def default = ctx.constructMonadic { param =>
[error]                                                ^
[error] /home/anned/github/magnolia/examples/shared/src/main/scala/default.scala:31:40: could not find implicit value for parameter monadic: mercator.Monadic[Monad]
[error]     def default = ctx.constructMonadic { param =>
[error]                                        ^
[error] three errors found
propensive commented 5 years ago

Without investigating, given that this error is occurring without your changes, I think the reason is that I didn't yet find time to publish a more recent version of Mercator that Magnolia needs. I've got a few higher priorities to sort to sort out first, but I'll get round to this later this week, I hope.

SethTisue commented 5 years ago

when you're fixing that, I think you'll want to modify your .travis.yml to compile the examplesJVM project (at least), which doesn't currently compile (because of 884eb078cbca57644e37acf8284d77cb269521a5, I think) — this turned up in the Scala community build

RafalSumislawski commented 5 years ago

149 should fix the compilation issue in examplesJVM

etaty commented 5 years ago

I had this issue, adding the types to constructMonadic solved it.

import mercator.Monadic

type Result[A] = Either[Throwable, A]
ctx.constructMonadic[Result, Any] { p =>
  //...
}

Maybe the PType should not be exposed?