-
Notifications
You must be signed in to change notification settings - Fork 19
Additional Types #36
Comments
We could pull these from Spire if we wanted, e.g. UByte. |
The biggest drawback I see with including this type is that we probably wouldn't be able to change the standard library to interoperate with it in useful ways, which would raise questions about what including it really did. I'm hoping that we can modularize Spire, which would make folks more likely to pull in unsigned number types when they need them. |
@non 👍 |
@non Would it make sense to have different typeclass instances for arithmetic operations on Byte, e. g. where one does signed arithmetic, one does unsigned, one does overflow checks, etc. instead of adding more types? |
So the type class idea is interesting. One problem I foresee is that If you have an idea about how to do this then let me know -- I'd be interested to see how it might work. |
Well, you could get rid of all operations defined on primitive types ... will probably be a pretty large job and with questionable compatibility. |
Is it wise to to make it easier to use the plethora of existing number types and further to add more number types to the language? Doug Crockford makes the case in this recent talk that JavaScript made a good call having only one number type. It's just that the wrong type was chosen, and he suggests a new single, decimal number type called DEC64. I realize that this approach might be a bit antagonistic to static typing but I find myself wishing that Scala were simpler here. What if Scala had only one or two basic number types with reasonable semantic, and the other types would be restrictions on those defined at the library level? Is there any value in this? I also wish that by default, and maybe without enabling flags, only maybe a Too radical? |
It's not that radical, though I know that Erik has some concerns about We already have value classes, and I think we could provide new number But on a syntactic level, Typelevel could do better. Currently, Scala Here's a casual suggestion for a way that that might happen:
Thoughts, anyone? I might give this a go... Jon On 21 November 2014 19:02, ebruchez [email protected] wrote:
Jon Pretty | @propensive |
I really like the idea of "pluggable numeric literals". I'm not sure how hard that would be to support, but it definitely makes sense. We might want to create a So, as @propensive suggests, I'm fairly critical of Crockford's DEC64 proposal. I'm not in a position to write a full rebuttal right now, but here's a quick list of bullet points:
Like I said, I don't necessarily have time to comprehensively analyze and critique DEC64. But I definitely don't think it would be the right move for Scala (Typelevel or otherwise) to standardize on it, especially since it is not a native type on the JVM. |
Of course, as an author of a library that adds many more numeric types, and promotes generic numeric programming, you could probably expect that this would be my response! 🎱 |
To resurrect this issue, please rework it as an issue/PR against Lightbend Scala (ie. scala/scala). |
see SIP-26, scala/docs.scala-lang#548 |
Non local returns aren't eliminated after inlined in 2.11 or 2.12 ``` ⚡ scala Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112). Type in expressions for evaluation. Or try :help. scala> @inlune def foo(a: => Any) = if ("".isEmpty) a else "" <console>:11: error: not found: type inlune @inlune def foo(a: => Any) = if ("".isEmpty) a else "" ^ scala> @inline def foo(a: => Any) = if ("".isEmpty) a else "" foo: (a: => Any)Any scala> class InlineReturn { def test: Any = foo(return "") } defined class InlineReturn scala> :javap -c InlineReturn#test public java.lang.Object test(); Code: 0: new #4 // class java/lang/Object 3: dup 4: invokespecial #32 // Method java/lang/Object."<init>":()V 7: astore_1 8: getstatic #36 // Field $line4/$read$$iw$$iw$.MODULE$:L$line4/$read$$iw$$iw$; 11: aload_1 12: invokedynamic #59, 0 // InvokeDynamic #0:apply:(Ljava/lang/Object;)Lscala/Function0; 17: invokevirtual #63 // Method $line4/$read$$iw$$iw$.foo:(Lscala/Function0;)Ljava/lang/Object; 20: goto 44 23: astore_2 24: aload_2 25: invokevirtual #66 // Method scala/runtime/NonLocalReturnControl.key:()Ljava/lang/Object; 28: aload_1 29: if_acmpne 39 32: aload_2 33: invokevirtual #69 // Method scala/runtime/NonLocalReturnControl.value:()Ljava/lang/Object; 36: goto 41 39: aload_2 40: athrow 41: goto 44 44: areturn Exception table: from to target type 8 20 23 Class scala/runtime/NonLocalReturnControl ``` ``` ⚡ ~/scala/2.11.8/bin/scala Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112). Type in expressions for evaluation. Or try :help. scala> @inline def foo(a: => Any) = if ("".isEmpty) a else "" foo: (a: => Any)Any scala> class InlineReturn { def test: Any = foo(return "") } defined class InlineReturn scala> :javap -c InlineReturn#test public java.lang.Object test(); Code: 0: new #4 // class java/lang/Object 3: dup 4: invokespecial #13 // Method java/lang/Object."<init>":()V 7: astore_1 8: getstatic #19 // Field .MODULE$:L; 11: new #21 // class InlineReturn$$anonfun$test$1 14: dup 15: aload_0 16: aload_1 17: invokespecial #24 // Method InlineReturn$$anonfun$test$1."<init>":(LInlineReturn;Ljava/lang/Object;)V 20: invokevirtual #28 // Method .foo:(Lscala/Function0;)Ljava/lang/Object; 23: goto 39 26: astore_2 27: aload_2 28: invokevirtual #31 // Method scala/runtime/NonLocalReturnControl.key:()Ljava/lang/Object; 31: aload_1 32: if_acmpne 40 35: aload_2 36: invokevirtual #34 // Method scala/runtime/NonLocalReturnControl.value:()Ljava/lang/Object; 39: areturn 40: aload_2 41: athrow Exception table: from to target type 8 26 26 Class scala/runtime/NonLocalReturnControl scala> :quit ```
Consider adding Unsigned variants of existing types
(unsigned Bytes, Shorts, Ints, Longs)
The text was updated successfully, but these errors were encountered: