structural-typing Questions

1

Solved

I've found somewhere an implementation of C# null coalescing operator '??': implicit def coalescingOperator[T](pred: T) = new { def ??[A >: T](alt: =>A) = if (pred == null) alt else pred } ...

2

Solved

This problem arose in a module I'm writing, but I have made a minimal case that exhibits the same behaviour. class Minimal[T](x : T) { def doSomething = x } object Sugar { type S[T] = { def doS...
Kaiserdom asked 27/4, 2012 at 0:34

2

Solved

If function accepts structural type, it can be defined as: def doTheThings(duck: { def walk; def quack }) { duck.quack } or type DuckType = { def walk; def quack } def doTheThings(duck: DuckTyp...
Fatalism asked 16/12, 2011 at 19:55

4

Solved

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 thi...
Germander asked 22/12, 2010 at 10:16

2

Solved

I needed some recursive structural type in some piece of code using with traits and the structural type as type parameter constraint. It worked fine, but later I learned Scala does not support recu...
Tychonn asked 4/9, 2010 at 19:29

2

Why cannot Scala optimize the following: a. implicit def whatever[A](a: A) = new { ... } to: b. class some$generated$name(a: A) { ... } implicit def whatever[A](a: A) = new some$generated$na...
Catricecatrina asked 6/10, 2010 at 2:25

1

I'm interested in the problem of conforming a specific type to a more general structural type. Consider the following examples: trait Sup trait Sub extends Sup type General = { def contra(o: Su...
Garofalo asked 12/8, 2010 at 20:21

3

Solved

I was reading (ok, skimming) Dubochet and Odersky's Compiling Structural Types on the JVM and was confused by the following claim: Generative techniques create Java interfaces to stand in for str...
Tarbox asked 17/8, 2010 at 2:43

2

Solved

Why does this print wtf? Does pattern matching not work on structural types? "hello" match { case s: { def doesNotExist(i: Int, x: List[_]): Double } => println("wtf?") case _ => println(...
Cwmbran asked 1/1, 2010 at 8:26

2

Solved

I'm trying to write a generic interpolate method that works on any type that has two methods, a * and a +, like this: trait Container { type V = { def *(t: Double): V def +(v: V): V } def in...
Schoolbook asked 8/7, 2010 at 7:48

1

Solved

I'm trying to define a structural type defining any collection that has an "add" method (for instance, a java collection). Using this, I want to define a few higher order functions that operate on ...
Befit asked 28/4, 2010 at 1:57

2

Solved

Let's have a following example: public class X { } public class Y { } public class Z { } public delegate IDictionary<Y, IList<Z>> Bar(IList<X> x, int i); public interface IFoo ...
Titanothere asked 7/4, 2010 at 7:23

8

Solved

Wikipedia used to say* about duck-typing: In computer programming with object-oriented programming languages, duck typing is a style of dynamic typing in which an object's current set of met...

© 2022 - 2024 — McMap. All rights reserved.