-
Notifications
You must be signed in to change notification settings - Fork 20
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
support a rational type #140
Comments
Can you point me to the relevant code? |
I think it's worth doing, but perhaps in a different way. I like that singleton-ops gives the "feel" of similar term algebraic behavior. The problem is that if we try to do in types We can change it so that when a macro finds an unsupported situation, e.g. So essentially, if we do this right, the type classes will be defined for the current op types (other than the new unique operations for Frac). I think new operations should use the same mechanism with new Op Ids. |
Let me clarify further. |
Perhaps to avoid implicit recursion we should add an |
I think we can probably make that work. I've had problems with If it was 2.13+ only, I'd feel pretty comfortable having implicits that can parse out sub-expressions, but that also is dicey, pre 2.13 (and is the reason coulomb works only on 2.13 plus) I'm a little hazy on how the internals of the OpMacro code works. Can the new type be detected inside to avoid a |
How does this happen now, with existing singleton types? The case of |
That's because it uses
The macro does not have upper-bounds. It's just one big case for everything. So it traverses the type tree calculates |
My current guess is that we just need to add the call to |
Thanks @soronpo! I'll play around with it when I get a chance |
Wow, this is really cool. If this actually works, singleton-ops will make it very easy to define recursive type operations: //Needs to be added to singleton-ops
trait AlternativeOp[N, S1, S2, S3] extends OpMacro[N, S1, S2, S3] {
type OutWide = None.type
val valueWide : OutWide = None
val isLiteral : Boolean = false
} //Fibonacci example
trait FibId
type Fib[P] = AlternativeOp[FibId, P, 0, 0]
implicit def doFib[P](implicit op : ITE[P == 1, 1, ITE[P == 0, 0, Fib[P - 1] + Fib[P - 2]]]) : Fib[P]{type Out = op.Out} = new Fib[P] {
override type Out = op.Out
override val value : op.Out = op.value
} |
Libra does this. I've wanted it in coulomb for a while (erikerlandson/coulomb#83). I could just port the code, but it seems like it might be a good fit for abstracting into singleton-ops, if stakeholders are agreeable.
The text was updated successfully, but these errors were encountered: