Re:Scala for Haskell programmers
by jrockway on Saturday January 23, 2010 @07:22PM
(#1072682)
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?
I am left with a few questsions:
Monoid was used as an example, but does Scala's type system support instances like:
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?
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) ... }