I was updating our app to latest 2.3-SNAPSHOT and saw that
numToJsExp was removed. I guess the correct way to now convert a
number to JsExp is to use Num(x)??
But this doesn't play so nice with Scala's type system afaics:
scala> case class Num(n:Number)
defined class Num
scala> def f:Option[Double] = None
f: Option[Double]
scala> Num(f.getOrElse(0.0))
<console>:9: error: type mismatch;
found : Any
required: java.lang.Number
Num(f.getOrElse(0.0))
^
Of course I can cast the value to Double, but this gets ugly fast. I
believe this could be solved by redefining Num:
case class Num2[T:Numeric](n:T)
scala> Num2(f.getOrElse(0.0))
res22: Num2[Double] = Num2(0.0)
I'm I missing something or should we make this change?
/Jeppe
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Hi
I was updating our app to latest 2.3-SNAPSHOT and saw that
numToJsExp was removed. I guess the correct way to now convert a
number to JsExp is to use Num(x)??
But this doesn't play so nice with Scala's type system afaics:
scala> case class Num(n:Number)
defined class Num
scala> def f:Option[Double] = None
f: Option[Double]
scala> Num(f.getOrElse(0.0))
<console>:9: error: type mismatch;
found : Any
required: java.lang.Number
Num(f.getOrElse(0.0))
^
Of course I can cast the value to Double, but this gets ugly fast. I
believe this could be solved by redefining Num:
case class Num2[T:Numeric](n:T)
scala> Num2(f.getOrElse(0.0))
res22: Num2[Double] = Num2(0.0)
I'm I missing something or should we make this change?
/Jeppe
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
> On Mon, Jan 31, 2011 at 7:06 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:
>
>> Hi
>>
>> I was updating our app to latest 2.3-SNAPSHOT and saw that
>>
>> numToJsExp was removed. I guess the correct way to now convert a
>> number to JsExp is to use Num(x)??
>>
>
> Actually, the implicits were moved from JE to the JsExp companion object.
Ok, just saw them commented out in JE.
>
>
>>
>> But this doesn't play so nice with Scala's type system afaics:
>>
>> scala> case class Num(n:Number)
>> defined class Num
>>
>> scala> def f:Option[Double] = None
>> f: Option[Double]
>>
>> scala> Num(f.getOrElse(0.0))
>> <console>:9: error: type mismatch;
>> found : Any
>>
>
> Sometime type inference is broken. This is one of those cases.
>
> I've added explicit constructors for Int, Float, Double, and Long which
> should address the problem.
Due to the broken type inference, this still needs two type annotations
(plus two more because the List constructor is not picked up) :
JsArray(dataset.series.map(s => JsArray(categories.map {cat => (s.valueOf(cat).getOrElse(0.0):Double):JsExp} : _*)) : _*)
The auxilary constructor taking a List on JsArray is not copied to the
companion object (see here http://www.scala-lang.org/node/976) so I
suggest we create a JsArray companion object?
I still think the change to Num I proposed works better with type
inference, at least in this example. Are there any drawbacks?
/Jeppe
/Jeppe
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
No :-) If you look at the comments to that ticket (and the commit)
you'll see that only a JsArray constructor was added.
/Jeppe
Hello,
As I see, JsExp is no longer subclass of scala.xml.SpecialNode in 2.3-
M1. As far as I understand this was done as part of issue #881 -
Improve Js conversion: https://www.assembla.com/spaces/liftweb/tickets/881-improve-js-conversion
. Am I right?
>
> /Jeppe
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.