typelevel / spire

Powerful new number types and numeric abstractions for Scala.
http://typelevel.org/spire/
MIT License
1.76k stars 242 forks source link

Simple example works on scastie but does not compile when using sbt #1301

Closed rseac closed 7 months ago

rseac commented 7 months ago

For the simple example:

import spire._
import spire.math._
import spire.implicits._

@main def hello: Unit =
  var c = Complex(4,3).sin
  println(c)

Gives an error:

[error] -- [E172] Type Error: C:\Users\hiren\code\fhe\src\main\scala\Main.scala:7:26 ---
[error] 7 |  val c = Complex(4,3).sin
[error]   |                          ^
[error]   |No given instance of type algebra.ring.Field[Int] was found for parameter f of method sin in class Complex
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Nov. 17, 2023, 10:39:55 a.m.

I wonder if this is a problem related to using Scala 3 vs Scala 2?

armanbilge commented 7 months ago

Can you share your build.sbt ?

armanbilge commented 7 months ago

I get the same error in Scastie.

https://scastie.scala-lang.org/hbICGwpvSTmBuXhvsrakqA

rseac commented 7 months ago

This was generated using the sbt new scala/scala3.g8.

val scala3Version = "3.3.1"

lazy val root = project
  .in(file("."))
  .settings(
    name := "fhe",
    version := "0.1.0-SNAPSHOT",

    scalaVersion := scala3Version,

    libraryDependencies += "org.typelevel" %% "spire" % "0.18.0",
    libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test
  )
armanbilge commented 7 months ago

I think you have to write it as Complex(4.0, 3.0).sin. I can't find any example where it works as you've written it (Scala 2 or Scala 3).

rseac commented 7 months ago

Ah :( sorry about that. That is the problem.