The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Scala shamelessly steals my idea!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Scala shamelessly steals my idea! Posted: Jun 13, 2008 9:25 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Scala shamelessly steals my idea!
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Remember this post where I toss out the idea of "static duck typing"?

Well, they've implemented it in Scala. Here's an example from the blog of Debasish Ghosh:
class Payroll {
  def makeSalarySheet(emps: List[{ def salary: Int }]) = {
    (0 /: emps)(_ + _.salary)
  }
}

In short, the makeSalarySheetTakes a list of objects that respond to the salary method (and must return an Int apparently).

The notation I originally came up with was this:
def foo(arg{:bar})
  ...
end

Where arg is an object that must respond to the bar method.

And here's what they came up with for Scala:
{ def salary: Int }

Not that dissimilar. A big difference, though, is that the "{ def salary: Int }" is some sort of anonymous type. The notion of an anonymous type is an interesting concept, and something I want to think about in more detail later.

I should also point out (courtesy of Mauricio Fernandez) that there is a library out there from Eivind Eklund that lets you do this, though I'm not a big fan of the interface.

The title of this blog post should not be taken seriously, btw.

Read: Scala shamelessly steals my idea!

Topic: Return of Syck Previous Topic   Next Topic Topic: Rails 2 Peepcode Updated w/ 2.1 Features

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use