« Return to Thread: Structural types and generics

Re: Structural types and generics

by Randall Schulz :: Rate this Message:

Reply to Author | View in Thread

On Monday July 6 2009, Brian Clapper wrote:
> On 7/6/09 5:42 PM, Viktor Klang wrote:
> > Why not try
> >
> > class StringTemplate(val varRegex : String, val resolver : (String)
> > => Option[String])
>
> Sure, I can do that. In fact, using a function reference did occur to
> me, as an alternative to structural typing. But I prefer passing an
> object rather than a function,

You're aware Scala functions are instances, right? They're all instances
of classes that implement one of the FunctionN traits (where N is the
function arity; traits with values of N from 0 through 22 are defined).


> for this particular API. Seems cleaner somehow--though I'll admit
> that's a thoroughly subjective judgment.

Ignoring implementation details like FunctionN, how is an object cleaner
than a function?


Randall Schulz

 « Return to Thread: Structural types and generics