Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tagging #676

Closed
puffnfresh opened this issue Mar 20, 2014 · 4 comments
Closed

Improve tagging #676

puffnfresh opened this issue Mar 20, 2014 · 4 comments
Milestone

Comments

@puffnfresh
Copy link
Member

I found this out over the past few weeks:

scala> Monoid[Int].append(Tags.Multiplication(2), Tags.Multiplication(3))
res0: Int = 5

The tags are lost!

This is probably more obvious for seeing what's happening:

scala> val x: Option[Int] @@ Tags.First = Tag(Some(1))
x: scalaz.@@[Option[Int],scalaz.Tags.First] = Some(1)

scala> val y: Option[Int] = x
y: Option[Int] = Some(1)

Tags are a subtype of the type they're tagging 👎

This comes down to how tags are implemented:

type @@[+T, Tag] = T with Tagged[Tag]

But we don't need the T on the right hand side to have unboxed tagging - here's an experiment I tried:

https://gist.github.com/puffnfresh/9377378

Would it be a problem to make tags not be a subtype?

@larsrh larsrh added this to the 7.1 milestone Mar 20, 2014
@puffnfresh
Copy link
Member Author

Another I accidentally found:

<puffnfresh> ! Tags.Zip(List(1, 2, 3)) *> Tags.Zip(List(3, 4, 5))
<multibot_>  List[Int] = List(3, 4, 5, 3, 4, 5, 3, 4, 5)

@larsrh
Copy link
Contributor

larsrh commented Jun 28, 2014

Your Zip example doesn't compile any more, so I guess this issue is resolved.

@larsrh larsrh closed this as completed Jun 28, 2014
@oxbowlakes
Copy link
Contributor

"Tags are a subtype of the type they are tagging"

One advantage of this is that an Array[Double @@ V] can be represented by an Array[Double] - post scalaz 7.1, our code has just fallen off a performance cliff :-(

Here's 7.0:

scala> import scalaz._; import Scalaz._; import Tags._; trait V
import scalaz._
import Scalaz._
import Tags._
defined trait V

scala> new Array[Double @@ V](1)
res0: Array[scalaz.@@[Double,V]] = Array(0.0)

scala> res0.getClass
res1: Class[_ <: Array[scalaz.@@[Double,V]]] = class [D

And here is 7.1

scala> new Array[Double @@ V](1)
res0: Array[scalaz.@@[Double,V]] = Array(null)

scala> res0.getClass
res1: Class[_ <: Array[scalaz.@@[Double,V]]] = class [Ljava.lang.Object;

@larsrh
Copy link
Contributor

larsrh commented Oct 31, 2014

Sounds like a case of correctness or performance: pick one. Unfortunately, I have no idea how to safely fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants