Live data from Hacker News

Scala for Haskell programmers

docs.google.com

1–6 of 6 posts

Re: Scala for Haskell programmers

#3
Scala is definitely one of the better functional languages for Java. (It's OO implementation is not that great, however.)

I am left with a few questsions:

Monoid was used as an example, but does Scala's type system support instances like:

   instance (Monoid a, Monoid b) => Monoid (a,b) where
      mempty = (mempty, mempty)
      ...
In this case, a mempty tuple is created by creating a mempty "a" and then a mempty "b". If you think about it, this is obvious, but the question is whether Scala's type system knows what "a" and "b" are at the right time, so it can delegate to the right "other" mempty.

(I ask, because I wrote a Haskell-style data structure module for Perl, but it is missing Monoid for this reason. We would know the types after mempty ran, but we can't run it without knowing the types. If only you could fold time back on itself...)

Also, they use the word "forAll" to describe type signatures; are higher-rank types allowable?

Re: Scala for Haskell programmers

#6
post #3

Scala is definitely one of the better functional languages for Java. (It's OO implementation is not that great, however.) I am left with a few questsions: Monoid was used as an example, but does Scala's type system support instances like: instance (Monoid a, Monoid b) => Monoid (a,b) where mempty = (mempty, mempty) ... In this case, a mempty tuple is created by creating a mempty "a" and then a mempty "b". If you thin…

No higher-rank types in Scala, I'm afraid.

As for the monoid instance:

def pairMonoid[A,B](a:Monoid[A],b:Monoid[B]) = new Monoid[(A, B)] { def empty = (a.empty, b.empty) ... }