Stephen Compall | 2 Mar 13:29 2015
Picon

Re: Sealed trait hierarchies and downcasting

On Mon, 2015-03-02 at 11:10 +0100, Rüdiger Klaehn wrote:
> sealed trait Foo
> 
> object Foo {
> 
>   def empty: Foo = ...
> 
>   def apply(...): Foo = ...
> 
>   private sealed trait Tree extends Foo
> 
>   private case class Leaf(...) extends Tree
> 
>   private case class Branch(...) extends Tree
> }
> 
> Basically have a sealed trait or sealed abstract class for the public
> interface, and then a completely
> private hierarchy that is the only implementation. This is a nice way
> to hide implementation details while still not having the overhead of
> boxing or the annoyance of wrapping in a value class.
> 
> However, a problem with this approach is that the compiler does not
> seem to know that a Foo must always be a Tree.

I don't see how you would lose any of the benefits you stated if `Tree`
simply wasn't included at all.  You would remove no overhead and reveal
no implementation details by eliminating `Tree`.

--

-- 
(Continue reading)

Rüdiger Klaehn | 2 Mar 11:10 2015
Picon

Sealed trait hierarchies and downcasting

Hi all,

one pattern I like to use is the following:

sealed trait Foo

object Foo {

  def empty: Foo = ...

  def apply(...): Foo = ...

  private sealed trait Tree extends Foo

  private case class Leaf(...) extends Tree

  private case class Branch(...) extends Tree
}

Basically have a sealed trait or sealed abstract class for the public
interface, and then a completely
private hierarchy that is the only implementation. This is a nice way
to hide implementation details while still not having the overhead of
boxing or the annoyance of wrapping in a value class.

However, a problem with this approach is that the compiler does not
seem to know that a Foo must always be a Tree. So this won't work:

def sumImpl(that: Tree) = ...

(Continue reading)

Steven Heidel | 2 Mar 05:59 2015
Picon

Unexpected compile error with reflective calls

Take a look at the following code:

import scala.language.reflectiveCalls

trait A {
  def sameName: Object
}

object B extends A {
  def sameName = new Object {
    def method = ???
  }

  def differentName = new Object {
    def method = ???
  }

  def main = {
    sameName.method // doesn't compile, "value call is not a member of Object"
    differentName.method // compiles
  }
}

I expected this to compile because I'm refining both the method sameName and differentName's Object with "method". The only difference is that sameName implements a method in trait A whereas differentName does not.

I'm assuming this is because type inference picks up Object for the return type of sameName from trait A instead of its actual type Object{def method: Nothing}. Is this a bug or a feature?

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tom S | 1 Mar 12:57 2015
Picon

Macro paradise in Eclipse via Ivy?

I need some help, please.  I'm trying to create macro annotations and am having trouble enabling macro
paradise in my Eclipse project (using Scala 2.11 in ScalaIDE).  I added an Ivy dependency for macro paradise:

<dependency org="org.scalamacros" name="paradise_2.11.5" rev="2.1.0-M5" />

...and when I resolve it downloads the JAR OK, but I get a compiler error when i try to use a macro annotation
saying I need to enable macro paradise.

Does anyone know how to do this in an Ivy-based project (without Maven or SBT)?  I tried configuring a macro
paradise compiler via these instructions but it doesn't work (Eclipse can't seem to find it):

http://stackoverflow.com/questions/7848521/how-to-get-scala-compiler-plugin-to-work-in-scala-ide

Thanks in advance!

--

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jiakui Wang | 27 Feb 00:54 2015
Picon

Strange problem with Scala 2.10

I got the variable c from previous code, and it behaves very strangely:

scala> c.asInstanceOf[Map[String, Any]].keys
res24: Iterable[String] = Set("label", "features")

scala> c.asInstanceOf[Map[String, Any]].apply("features")
java.util.NoSuchElementException: key not found: features
at scala.collection.MapLike$class.default(MapLike.scala:228)
at scala.collection.AbstractMap.default(Map.scala:58)
at scala.collection.MapLike$class.apply(MapLike.scala:141)
at scala.collection.AbstractMap.apply(Map.scala:58)
at .<init>(<console>:14)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:904)
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102)
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:77)
at sbt.Console.sbt$Console$$console0$1(Console.scala:23)
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
at sbt.TrapExit$.sbt$TrapExit$$executeMain$1(TrapExit.scala:33)
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)


Any idea about the problem?

Thanks



--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Clayton Wohl | 24 Feb 06:37 2015
Picon

Advice on Suggesting Scala to a Java Company?

I am interviewing for several developer positions that are using more traditional Java development stacks including Java 6, Spring Beans, Spring MVC, Tomcat, Hibernate, etc. In 2015, doing new projects confined to these older frameworks seems less productive, I'd be less excited about it, and it might not be the best idea. There are other companies already using better tool chains, but these jobs have other desirable qualities, and it's worth asking how flexible they are on this issue.

Can anyone offer advice for tactfully suggesting the possibility of Scala and associated Typesafe technologies such as Akka, Spray, and possibly Slick?

Some employers may have already made their tool chain decisions and not be interested in other ideas and that is perfectly fine. But other employers may be open to suggestions and might agree with some benefits and this is a reasonable time to ask.

To another programmer I would say the benefits of Scala are that it's a higher level, more elegant tool relative to base Java that allows developers to implement logic with less code that is more provably correct at a compiler level and lets you use more advanced frameworks. The advantage of Akka is easy to articulate. It's a concurrency framework centered around two ideas: non-blocking asynchronous concurrency and immutable message passing concurrency instead of shared state concurrency. And while you can do those without Akka, Akka provides a cleaner standardized framework for that style of programming. I can articulate one benefit of Slick over Hibernate: rather than express queries and data operations in untyped text strings (hsql), you use a compiler checked syntax. Beyond that, Slick looks much better than Hibernate beyond that, but I can not articulate further specific reasons (I've read the presentation slides of course)

Can anyone add any other high level succinct advantages of Scala and associated technologies over Java/Spring/Hibernate?

BTW, I am sure there are languages and tools other than Scala that are as good or even better, and while I'd be happy to join teams using those, I don't feel experienced enough in other technologies to champion them.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hadil Sabbagh | 16 Feb 14:59 2015
Picon

scala/AnyRef and scala/Any -- need some feedback

I am currently working on a project to compile Scala JVM code to CUDA. I have need to preload some classes into my ClassLoader, namely scala/AnyRef and scala/Any. I have been reviewing the source code and it does not appear that the implementations of these components match what is in the code.

Can a member of the Scala team explain to me how these are implemented and what I should find in the scala-library-2.11..5.jar file for them? I would be most grateful.

If you are intereesting in seeing my progress thus far, it in on Github as GrayMatterTechnology/rootbeerfloat.


Thanks,
Hadil G. Sabbagh, Ph.D.
Gray Matter Technology, LLc

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
SpiderPig | 15 Feb 07:39 2015
Picon

Fast execution of scripts

I often use Scala in script mode and have always been annoyed at the slow compile speed. It takes about 2 - 3 seconds for a script (run with "scala script.scala") to start.
But recently I learned there is a way to start a scala script much faster.

Here is some example code that demonstrates this. First you start ScriptServer.scala and afterwards you can run any scala script with "java RunScript script.scala". The first time it still takes 2 seconds but all future invocations run in less than 200 ms.
Now that raises the question if it is possible to add a command line option to scala that lets you run scripts that fast. There probably is some drawback to this approach I'm not aware of but I'm guessing it would work at least for most small scripts.

ScriptServer.scala:
import javax.script._
import java.net._

val engine = new ScriptEngineManager().getEngineByName("scala")

val ss = new ServerSocket(10123)

while(true) {
  val so = ss.accept()
  val in = scala.io.Source.fromInputStream(so.getInputStream)
  val script = engine.asInstanceOf[Compilable].compile(in.mkString)
  script.eval()
}.

RunScript.java:
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.file.*;
import java.util.List;

public class RunScript {
  public static void main(String[] args) throws Exception {
    String name = args[0];
    List<String> lines = Files.readAllLines(Paths.get(name));
    PrintWriter out = new PrintWriter(new Socket("localhost", 10123).getOutputStream());
    for(String line: lines) {
      out.println(line);
    }
    out.flush();
    out.close();
  }
}


--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
David Roon | 12 Feb 10:35 2015
Picon

scala 2.12 M1

Hi everyone,
I am trying to see what the status is for scala 2.12.

When I read the roadmap it sounds really cool and I am looking forward to play with it. 

My issue is that the first milestone was planned end of november 2014 and we are now 3 months later and I see no sign of this version. 

Did I miss something? Is there blocking issues that prevent the first milestone to come? 

Keep up the good work!

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Aravindh S | 8 Feb 06:07 2015

Static Reflection in Scala

Hi  All, I have been trying to achieve the following in scala for quite sometime now, but was not able to do so.  I am looking for a way to pass the name of a val inside a case class along with its type to another method. Below is an example:

case class Person(name:String, age:Int)

object Sample{
     def apply[T]={}
     def set(???) = ???
}


I would like the set method to be used like
Sample[Person].set(p => p.name = "random name") or simply Sample[Person].set(_.name="random name")

The above ideally wont work because I am trying to re assign to a val. But Would like to have something like this. I need to capture the name of the val, type of the val inside the set method and would want the compiler to do a type check when the above method is invoked. 

In C#, We have the expression API which helps in static compile time reflection which will allow you to define methods like above. How do I accomplish the above in scala?


Thanks
Aravindh.S

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Khushil Dep | 7 Feb 19:28 2015
Picon

FP Software Engineers

Hi 

I'm looking for functional software engineers who want to work in Scala, Clojure or Haskell - Scala preferred.

Please see https://hackerjobs.co.uk/jobs/2015/2/4/guardtime-experienced-functional-software-engineer for full details

This isn't an agency posting, you'll be working for me direct.  Please do contact me if you live in the EU/UK area.

Thanks.

-
Khush

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gmane