« first day (472 days earlier)      last day (421 days later) » 

12:14 AM
0
Q: Java Singleton has different toString() value

bheusslerI have a classic singleton implemented in java public class ClassicSingleton { private static ClassicSingleton instance = null; private ClassicSingleton() {} ; public static ClassicSingleton getInstance() { if (instance == null) return new ClassicSingleton(); ...

 
 
10 hours later…
10:04 AM
@rightfold I was trying to move your Scala questions to the FP room, but... I'm not a room owner anymore :(
 
user1804599
@Mysticial HELP
 
@rightfold You could just have asked them in the FP room the first place ;)
 
user1804599
Anyway path-dependent types are not specific to functional programming. :P
 
user1804599
Java Sucks has had less activity so we should move the messages to there.
 
user1804599
We can prove it by making clear why we need Scala. :P
 
10:11 AM
I'm sure nobody who hasn't done some work in Scala even realizes there is such a thing as path-dependent types.
 
user1804599
:P
 
8 messages moved from Lounge<C++>
 
user1804599
Maybe -Xexperimental works.
 
user1804599
trait ID_UserPair {
  val id: user.ID
  val user: User
}

object test {
  def foo(): ID_UserPair =
    new ID_UserPair {
      override val user = User("", null)
      override val id = user.ID(42)
    }
}
 
user1804599
This works. :3
 
user1804599
10:20 AM
Let’s see.
 
user1804599
Oh my god it works.
 
user1804599
Except I now manually have to implement equality and hashing on ID_UserPair. :{
 
So... no anonymous case classes in Scala?
 
user1804599
in Functional Programming, 23 mins ago, by rightfold
case class User(emailAddress: String, passwordHash: PasswordHash) {
    case class ID(value: Int)
}
// now I want to do this, but I get a complaint from the compiler that method-dependent types are not supported:
case class ID_UserPair(id: user.ID, user: User)
 
You're probably better off asking on SO, because I have no experience with path-dependent and method-dependent and whatnot-dependent types.
 
user1804599
10:38 AM
I can derive from Product2 I guess.
 
user1804599
trait Equality {
  this: Product =>

  override def equals(that: Any) =
    canEqual(that) && that.asInstanceOf[Product].productIterator.zip(productIterator).forall{ case (a, b) => a == b }

  override def hashCode() = {
    var code = productPrefix.hashCode()
    val arr = productArity
    var i = 0
    while (i < arr) {
      val elem = productElement(i)
      code = code * 41 + (if (elem == null) 0 else elem.hashCode())
      i += 1
    }
    code
  }
}
 
user1804599
This should work.
 
Where is part2?
 
user1804599
I have no idea!
 
Maybe type checking is so complex that it takes them more than 3 years to make part2?
 
user1804599
10:50 AM
:D
 
user1804599
WTF.
 
user1804599
Why does this not work.
 
user1804599
It doesn’t even call that equals function. :S
 
@rightfold Does it work if hashCode() returns a constant? Then the error is inside hashCode().
 
user1804599
Oh wait, it does call hashCode.
 
user1804599
10:53 AM
@FredOverflow Nope, doesn’t work.
 
user1804599
And even when hashCode returns a constant, equals still isn’t being called.
 
Can you provide an SSCCE?
While you work on that, I'm gonna make a salad.
 
user1804599
Nevermind. :3
 
user1804599
I was comparing expectedID_UserPair to Some(expectedID_UserPair). XD
 
user1804599
@FredOverflow I’m gonna make noodles.
 
11:02 AM
2
Q: Singleton Pattern: Using Enum Version

RNI2013I do not understand how to implement the Enum Version of the Singleton pattern. Below is an example of implementing "traditional" approach to using the Singleton pattern. I would like to change it to use the Enum version but i am not sure how? public class WirelessSensorFactory implements ISens...

 
@rightfold A sane type system would not allow these comparisons.
static type sanity
 
user1804599
Well, there’s implicit upcast.
 
user1804599
scalac usually gives a warning but I’m using ScalaTest’s should be, not ==.
 
user1804599
Still, this is too much boilerplate:
 
user1804599
override def canEqual(that: Any) =
  that.isInstanceOf[ID_UserPair]

override def _1 = id
override def _2 = user
 
user1804599
11:16 AM
Macros to the rescue?
 
user1804599
I guess I can move canEqual to Equality.
 
489
Q: Does Functional Programming Replace GoF Design Patterns?

JulietSince I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong claim: Most people I've met have read the D...

Why did I never see this question before?
 
user1804599
Hmm. Moving canEqual to Equality works with CRTP. :)
 
Scala has templates?
 
user1804599
@FredOverflow You don’t “need” design patterns.
 
user1804599
11:20 AM
They arise coincidentally.
 
So what? C is Turing complete, yet it has no lambda functions.
 
user1804599
No, but the term CRTP is used with non-template generics as well.
 
Oh, I thought it was C++ specific. T = template, right?
 
user1804599
Yes, so?
 
user1804599
I think the as-if rule must be removed from the C++ standard.
 
user1804599
11:24 AM
It’s already implied by the lack of implementation details.
 
Write a proposal :)
 
user1804599
:D
 
1:02 PM
0
Q: "one word" singleton access in Android / Java?

Joe BlowJava friends, in objectiveC you access a singleton more or less like this, [State sharedState] normally you have a macro, once only, at the top the project (typically the "Prefix.pch" file in iOS), #define STATE [State sharedState] Then throughout the project, anywhere, you just type STATE....

 
 
1 hour later…
2:17 PM
@rightfold Gna, all the compiler videos I have downloaded are almost incomprehensible due to the Indian accent :-(
 
user1804599
I want to create a subclass of TreeMap lol.
 
user1804599
With fixed key and value types.
 
user1804599
Surprise! SortedMapFactory takes a C[A, B], not a C!
 
user1804599
How fun.
 
user1804599
Scala sucks.
 
user1804599
2:19 PM
Luckily MapBuilder doesn’t. Let’s see.
 
user1804599
private object HeaderOrdering extends Ordering[String] {
  override def compare(x: String, y: String) =
    x.compareToIgnoreCase(y)
}

class HeaderMap private (original: TreeMap[String, Set[String]])
  extends TreeMap[String, Set[String]]()(HeaderOrdering) {
  override implicit def ordering = HeaderOrdering
}

object HeaderMap {
  def empty = new HeaderMap(TreeMap.empty)

  def apply(elems: (String, Set[String])*) = (newBuilder ++= elems).result

  def newBuilder = new mutable.MapBuilder[String, Set[String], HeaderMap](empty)
 
user1804599
This should work, lol.
 
@rightfold You could take two generic parameters for your class and simply ignore them ;)
 
user1804599
No, that would be a horrible hack.
 
user1804599
But now I should be able to write a toHeaderMap function with ease!
 
user1804599
2:29 PM
Yay, it works omg.
 

« first day (472 days earlier)      last day (421 days later) »