This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Thoughts on scala.Zero, and algebraic structures in the scala library

8 replies
matthw
Joined: 2009-08-23,
User offline. Last seen 3 years 9 weeks ago.

Spotted this in the recent scala additions:

http://lampsvn.epfl.ch/trac/scala/changeset/19291/scala/trunk/src/librar...

My thoughts:

- To call something a 'Zero' on a particular type, doesn't make much
sense (and isn't much use) without the context of a (typically
associative) binary operation on that set which it's a zero of
- 'Identity' is a better term than 'zero' in this general context, in
particular it may be a left identity or a right identity or both
- There's a name for sets with an identity and an associative binary
operation - a Monoid
- Monoids would actually be pretty useful to have in the library, and
I think each of these implicit Zero instances should rather be a
Monoid instance, supplying the binary operation as well as its identity

Found an example of a monoid class (and implicit monoids) mentioned
here: http://www.scala-lang.org/node/114

So yeah, just wondering what the rationale here was, and more
generally, what the philosophy is about modelling algebraic structures
in the scala library.

Personally I'd love to see a really well-engineered set of classes for
algebraic structures made available, and it pains me a bit to see odds
and ends of mathematical structure done in the library in a rather ad-
hoc way which could be quite hard to make really consistent / coherent
further down the road once everyone's relying on them. This is what
happened with haskell, which is rather a sad tale. There are a few
alternative Preludes available for haskell now which 'do it right',
but at the cost of replacing the core of the standard library everyone
else is using.

Happy to help out here if anyone feels code would speak louder than
words :)

-Matt

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sca

On Wed, Nov 04, 2009 at 01:58:05AM +0000, Matthew Willson wrote:
> Spotted this in the recent scala additions:

You'll be happy to know that as is the rule more than the exception with
me lately, I'll be reverting it in the near future.

Ben Hutchison 3
Joined: 2009-11-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc

On Wed, Nov 4, 2009 at 12:58 PM, Matthew Willson
wrote:
> So yeah, just wondering what the rationale here was, and more generally,
> what the philosophy is about modelling algebraic structures in the scala
> library.
>
> Personally I'd love to see a really well-engineered set of classes for
> algebraic structures made available, and it pains me a bit to see odds and
> ends of mathematical structure done in the library in a rather ad-hoc way
> which could be quite hard to make really consistent / coherent further down
> the road once everyone's relying on them.

I agree with the above.

I'd like to see the Scala library design ruthlessly mine Haskell for
its ideas and wisdom, especially with respect to algebraic structures.

For an example of Haskell Wisdom, see the Typeclassopedia in:
http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf

-Ben

Eastsun 2
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sca

Scala 2.8 has some other Type relate to algebraic structures in my opinion,
e.g. Fractional, Integral, Numeric ,(Addable ?)..

Matthew Willson-3 wrote:
>
> Spotted this in the recent scala additions:
>
> http://lampsvn.epfl.ch/trac/scala/changeset/19291/scala/trunk/src/librar...
>
> My thoughts:
>
> - To call something a 'Zero' on a particular type, doesn't make much
> sense (and isn't much use) without the context of a (typically
> associative) binary operation on that set which it's a zero of
> - 'Identity' is a better term than 'zero' in this general context, in
> particular it may be a left identity or a right identity or both
> - There's a name for sets with an identity and an associative binary
> operation - a Monoid
> - Monoids would actually be pretty useful to have in the library, and
> I think each of these implicit Zero instances should rather be a
> Monoid instance, supplying the binary operation as well as its identity
>
> Found an example of a monoid class (and implicit monoids) mentioned
> here: http://www.scala-lang.org/node/114
>
> So yeah, just wondering what the rationale here was, and more
> generally, what the philosophy is about modelling algebraic structures
> in the scala library.
>
> Personally I'd love to see a really well-engineered set of classes for
> algebraic structures made available, and it pains me a bit to see odds
> and ends of mathematical structure done in the library in a rather ad-
> hoc way which could be quite hard to make really consistent / coherent
> further down the road once everyone's relying on them. This is what
> happened with haskell, which is rather a sad tale. There are a few
> alternative Preludes available for haskell now which 'do it right',
> but at the cost of replacing the core of the standard library everyone
> else is using.
>
> Happy to help out here if anyone feels code would speak louder than
> words :)
>
> -Matt
>
>

-----
My scala solutions for http://projecteuler.net/ Project Euler problems:
http://eastsun.javaeye.com/category/34059 Click here

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc
The good news is that you can layer these on top of Scala with the Scalaz library. Runar and Tony describe the relationship here, in response to an earlier message from Ben: http://groups.google.com/group/scalaz/browse_thread/thread/b686d161d9e5cd78/35ecff815569a2a1?hl=en&lnk=gst&q=implicit#35ecff815569a2a1

The limited resources of the core team may be better applied to the compiler rather than the contentious task of 'haskell-ification' of the standard lib.

-jason

On Wed, Nov 4, 2009 at 4:04 AM, Ben Hutchison <brhutchison [at] gmail [dot] com> wrote:
I'd like to see the Scala library design ruthlessly mine Haskell for
its ideas and wisdom, especially with respect to algebraic structures.

For an example of Haskell Wisdom, see the Typeclassopedia in:
http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf

-Ben

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc
This is all fine and dandy, but how about Money?

On Wed, Nov 4, 2009 at 8:11 AM, Jason Zaugg <jzaugg [at] gmail [dot] com> wrote:
The good news is that you can layer these on top of Scala with the Scalaz library. Runar and Tony describe the relationship here, in response to an earlier message from Ben: http://groups.google.com/group/scalaz/browse_thread/thread/b686d161d9e5cd78/35ecff815569a2a1?hl=en&lnk=gst&q=implicit#35ecff815569a2a1

The limited resources of the core team may be better applied to the compiler rather than the contentious task of 'haskell-ification' of the standard lib.

-jason

On Wed, Nov 4, 2009 at 4:04 AM, Ben Hutchison <brhutchison [at] gmail [dot] com> wrote:
I'd like to see the Scala library design ruthlessly mine Haskell for
its ideas and wisdom, especially with respect to algebraic structures.

For an example of Haskell Wisdom, see the Typeclassopedia in:
http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf

-Ben




--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Blog: klangism.blogspot.com
Twttr: viktorklang
Code: github.com/viktorklang
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc
If you think Paul was in any way pursuing a "haskell-ification" of anything, I have some bottom land you might be interested in...
AFAIK, the whole purpose of his Zero was being able to generalize the implementation of certain parameterized classes.

On Wed, Nov 4, 2009 at 5:11 AM, Jason Zaugg <jzaugg [at] gmail [dot] com> wrote:
The good news is that you can layer these on top of Scala with the Scalaz library. Runar and Tony describe the relationship here, in response to an earlier message from Ben: http://groups.google.com/group/scalaz/browse_thread/thread/b686d161d9e5cd78/35ecff815569a2a1?hl=en&lnk=gst&q=implicit#35ecff815569a2a1

The limited resources of the core team may be better applied to the compiler rather than the contentious task of 'haskell-ification' of the standard lib.

-jason

On Wed, Nov 4, 2009 at 4:04 AM, Ben Hutchison <brhutchison [at] gmail [dot] com> wrote:
I'd like to see the Scala library design ruthlessly mine Haskell for
its ideas and wisdom, especially with respect to algebraic structures.

For an example of Haskell Wisdom, see the Typeclassopedia in:
http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf

-Ben




--
Daniel C. Sobral

Veni, vidi, veterni.
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc
For the record, I used the term "haskell-ification" in reference to Ben's suggested direction, not in specific reference to the all-to-brief appearance of Zero, of which I was rather fond. :)

-jason

On Wed, Nov 4, 2009 at 11:59 AM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
If you think Paul was in any way pursuing a "haskell-ification" of anything, I have some bottom land you might be interested in...
AFAIK, the whole purpose of his Zero was being able to generalize the implementation of certain parameterized classes.
matthw
Joined: 2009-08-23,
User offline. Last seen 3 years 9 weeks ago.
Re: Thoughts on scala.Zero, and algebraic structures in the sc

> AFAIK, the whole purpose of his Zero was being able to generalize
> the implementation of certain parameterized classes.

Perhaps something like scala.Monoid could fill the same role? a
generalised zero is a whole lot more useful if there's a generalised
'plus' to use with it... although:

> The limited resources of the core team may be better applied to the
> compiler rather than the contentious task of 'haskell-ification' of
> the standard lib.

Certainly. I wasn't suggesting that the standard library necessarily
needs these things in it. Merely that, where the standard library DOES
choose to implement algebraic abstractions, it takes some care to get
them right, so they can be built upon cleanly by others.

In particular I wasn't suggesting borrowing wholesale from haskell -
haskell gets quite a few things wrong, eg its 'Num' class.

Cheers
-Matt

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland