language-design

Reified generics in Scala on .NET/CLR

一个人想着一个人 提交于 2019-12-03 08:04:14
Scala (at least on the JVM ) uses type erasure for Java compatibility. This feature is widely held to suck . Fixing this would be difficult on the JVM . In contrast to the JVM situation, .NET supports reified generics. Does Scala's .NET implementation use them? If not, could it, or else what issues would using reification cause? It's work in progress, carefully not to break Scala semantics between JVM and .NET. I asked this question back in 2011 on the scala-tools mailinglist and the answer is given by Miguel Garcia in which he outlines the big picture: Some quotes: (1) What the Scala.Net

Java static imports

北城余情 提交于 2019-12-03 06:28:13
问题 Just by experiment I discovered that Java non static methods overrides all same named methods in scope even at static context. Even without allowing parameter overloading. Like import java.util.Arrays; import static java.util.Arrays.toString; public class A { public static void bar(Object... args) { Arrays.toString(args); toString(args); //toString() in java.lang.Object cannot be applied to (java.lang.Object[]) } } I can't find anything about this in spec. Is this a bug? If it isn't, are

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

半世苍凉 提交于 2019-12-03 06:20:14
Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as Int32 on the first line. Then when I try to cast as something other than Int32 InvalidCastException is thrown. I suppose this means that I am trying to unbox val as Int64 when it is actually an Int32? Still seems strange. Couldn't the cast unbox the value and then try

unique_ptr - major improvement?

六月ゝ 毕业季﹏ 提交于 2019-12-03 05:46:50
问题 In the actual C++ standard, creating collections satisfying following rules is hard if not impossible: exception safety, cheap internal operations (in actual STL containers: the operations are copies), automatic memory management. To satisfy (1), a collection can't store raw pointers. To satisfy (2), a collection must store raw pointers. To satisfy (3), a collection must store objects by value. Conclusion: the three items conflict with each other. Item (2) will not be satisfied when shared

Writing a mini-language

时间秒杀一切 提交于 2019-12-03 05:23:41
问题 I have an application that needs to allow users to write expressions similar to excel: (H1 + (D1 / C3)) * I8 and more complex things like If(H1 = 'True', D3 * .2, D3 * .5) I can only do so much with regular expressions. Any suggestions as to the right approach to doing this as well as any resources I can learn from would be much appreciated. Thanks! 回答1: Some other question, you will find hints in: How to write a programming language? Learning to write a compiler Writing a compiler for a DSL

Clojure Protocols vs Scala Structural Types

谁都会走 提交于 2019-12-03 05:14:00
问题 After watching the interview with Rich Hickey on Protocols in Clojure 1.2, and knowing very little about Clojure, I have some questions on Clojure Protocols: Are they intended to do the same thing as Structural Types in Scala? What benefits do Protocols have over Structural Types (performance, flexibility, code clarity, etc.)? Are they implemented through reflections? Questions on interoperability with Scala: Can Protocols be used instead of Structural Types in Scala? Can they be extended (if

Are there languages without “null”?

风格不统一 提交于 2019-12-03 05:07:12
There are many people who think that the concept of the special value null (as it is used in lanuages like C, Java, C#, Perl, Javascript, SQL etc.) is a bad idea. There are several questions about this on SO and P.SE, such as Best explanation for languages without null and Are null references really a bad thing? . However, I could not find any language that does without them. All the languages I'm familiar with have null , or something similar (e.g. "undefined" in Perl). I realize that proably every language needs some way to express "absence of a value". However, instead of having "null" or

Creating a small programming language for beginners

不想你离开。 提交于 2019-12-03 04:47:09
I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with it. I have made the Hello world project in it, but how would I make a compiler in it? Are there any easy ways of creating a small programming language, I have heard of translating a language as in taking, e.g., Write() and making the computer understand it as Print() . Is this be possible?. My take on this is that the simpler approach is not to mess

Haskell “collections” language design

六眼飞鱼酱① 提交于 2019-12-03 04:46:37
Why is the Haskell implementation so focused on linked lists? For example, I know Data.Sequence is more efficient with most of the list operations (except for the cons operation), and is used a lot; syntactically, though, it is "hardly supported". Haskell has put a lot of effort into functional abstractions, such as the Functor and the Foldable class, but their syntax is not compatible with that of the default list. If, in a project I want to optimize and replace my lists with sequences - or if I suddenly want support for infinite collections, and replace my sequences with lists - the

Scala's .type and Java's .class literal

纵然是瞬间 提交于 2019-12-03 04:46:17
问题 I wonder from a language design perspective why Scala has removed Java's class literal (e. g. String.class ) and replaced it with classOf[String] , but has then added a "type literal" with its Singletons like Singleton.type instead of something like typeOf[Singleton] ? 回答1: Here is my rationalization: classOf[T] classOf is defined in Predef as a function with this signature: def classOf[T]: Class[T] Although it's implemented by the compiler, using the function syntax is possible without