I've been trying to work out how to implement Church-encoded data types in Scala. It seems that it requires rank-n types since you would need a first-class const function of type forAll a. a -> (forAll b. b -> b).
However, I was able to encode pairs thusly:
import scalaz._
trait Compose[F[_],G[_]] { type Apply = F[G[A]] }
trait Closu...
I know that to be Traversable, you need only have a foreach method. Iterable requires an iterator method.
Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable....
Can anybody provide some details on <:< operator in scala.
I think:
if(apple <:< fruit) //checks if apple is a subclass of fruit.
Are there any other explanations? I see many definitions in the scala source file.
...
What does the following error message mean?
cannot override a concrete member
without a third member that's
overridden by both (this rule is
designed to prevent ``accidental
overrides'');
I was trying to do stackable trait modifications. It's a little bit after the fact since I already have a hierarchy in place and I'm tryi...
Consider this simplified application domain:
Criminal Investigative database
Person is anyone involved in an investigation
Report is a bit of info that is part of an investigation
A Report references a primary Person (the subject of an investigation)
A Report has accomplices who are secondarily related (and could certainly be primary i...
I have a basic type system type mismatch problem:
I have a class with a method
def Create(nodeItem : NodeItem) = {p_nodeStart.addEndNode(nodeItem)}
where p_nodeStart is NodeCache
class NodeCache[END_T<:BaseNode] private(node: Node) extends BaseNode {
def addEndNode(endNode : END_T) = {this.CACHE_HAS_ENDNODES.Create(endNode)}
and th...
What is the most efficient way to create emtpy ListBuffer ?
val l1 = new mutable.ListBuffer[String]
val l2 = mutable.ListBuffer[String] ()
val l3 = mutable.ListBuffer.empty[String]
There are any pros and cons in difference ?
...
Option is implicitly convertible to an Iterable - but why does it not just just implement Iterable directly:
def iterator = new Iterator[A] {
var end = !isDefined
def next() = {
val n = if (end) throw new NoSuchElementException() else get
end = true
n
}
def hasNext = !end
}
EDIT: In fact it's even weider than that...
Is it possible to create types like e.g. String(20) in scala?
The aim would be to have compiler checks for things like:
a: String(20)
b: String(30)
a = b; // throws a compiler exception when no implicit conversion is available
b= a; // works just fine
Note: It doesn't need to be/named String
...
Hi StackOverflow Community!
First of all: I'm at Scala 2.8
I have a slight Issue while using pattern matching on XML elements. I know I can do smth. like this:
val myXML = <a><b>My Text</b></a>
myXML match {
case <a><b>{theText}</b></a> => println(theText)
case _ =>
}
This is the sort of example I find everywhere on the net ...
I would like to know if there is any way that I could build a very simple GUI app (it doesn't even have to look good) that will run on a fresh install of Windows Vista and OS X with no other installations needed by the user. I would perfer not to use Java (just out of personal programming preference). I will use it though, if it is the o...
Hi.
I want to use object instances as modules/functors, more or less as shown below:
abstract class Lattice[E] extends Set[E] {
val minimum: E
val maximum: E
def meet(x: E, y: E): E
def join(x: E, y: E): E
def neg(x: E): E
}
class Calculus[E](val lat: Lattice[E]) {
abstract class Expr
case class Var(name: String) extends...
pathTokens match {
case List("post") => ("post", "index")
case List("search") => ("search", "index")
case List() => ("home", "index")
} match {
case (controller, action) => loadController(http, controller, action)
case _ => null
}
I wanted contiguous match. but got compile error. :(
(pathTokens match {
case List("post") => ("pos...
As far as I can see the key advantage of dynamic languages like Ruby or Python over Java/Scala/C# etc is "hot" applying of your changes to source code to the running application. What are the frameworks for JVM or .NET that support the same workflow - apply changes to configuration and source code on the fly? Can they also watch changes ...
You have:
val array = new Array[Array[Cell]](height, width)
How do you initialize all elements to new Cell("something")?
Thanks,
Etam (new to Scala).
...
I am generating the scala AST using the following code:
val setting = new Settings(error)
val reporter = new ConsoleReporter(setting, in, out) {
override def displayPrompt = ()
}
val compiler = new Global(setting, reporter) with ASTExtractor{
override def onlyPresentation = true
}
//setting.PhasesSetting("...
This is the same question for older version of Scala, but they say that Eclipse plugin has been improved vastly. Is it the best IDE now? How do different Scala IDE compare today?
...
I sweated over the question above. The answer I'm going to supply took me a while to piece together, but it still seems hopelessly primitive and hacky compared to what one could do were completion to be redesigned to be less staticky. I'm almost afraid to ask if there's some good reason that completion logic seems to be completely divo...
Hello I am working with the Kate editor based on the lack of other good tools for Scala development, I am also using IntelliJ however it still has some bugs, and are slow enough to make me impatient.
I have just startet using both Kate and SBT, and in that regard I have a little challenge I hope there is an answer for out there on "The...
In scala, you often use an iterator to do a for loop in an increasing order like:
for(i <- 1 to 10){ code }
How would you do it so it goes from 10 to 1? I guess 10 to 1 gives an empty iterator (like usual range mathematics)?
I made a scala script which solves it by calling reverse on the iterator, but it's not nice in my opinion, is ...