Re: [scala-user] How to use Ordered with traits and primitive number types?

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: [scala-user] How to use Ordered with traits and primitive number types?

by Ricky Clarkson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Maybe we're drifting towards an OO vs Functional rift in this conversation...

And towards scala-debate.  I meant to do that on my last post.

> If you want to do the /same thing/ to several different objects, you can either
>
> [OO-] imbue the various objects with the ability to do that thing ,
> which is easiest to do via traits & mixin composition

The disadvantage to this is that the ability to do that thing might
only be desired within a certain scope.  Implicit conversions let you
add the ability without making it available to code that doesn't
import the conversion, and they work against objects not created by
the code that requires that ability, e.g., Strings.

> [Functional-] define functions independently of the target objects,
> and expose their data via some generic form.

There's nothing to stop a value containing a function, if that makes
more sense for a case.

> Lets get specific. The use-case the started this off was a desire to
> define a specialized form of ordering over homogeneous containers of
> ordered items (basically, vectors).

See Ordering in 2.8.

> To me, that just doesnt seem as nice. Maybe Im simply OO brainwashed...

You're assuming that functions have to be standalone.  Ordering is
basically a group of functions given a name.  It seems a good example
to me.

--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@...
Google Wave: ricky.clarkson@...

Re: [scala-user] How to use Ordered with traits and primitive number types?

by Ben Hutchison-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Nov 9, 2009 at 10:47 PM, Ricky Clarkson
<ricky.clarkson@...> wrote:

>> If you want to do the /same thing/ to several different objects, you can either
>>
>> [OO-] imbue the various objects with the ability to do that thing ,
>> which is easiest to do via traits & mixin composition
>
> The disadvantage to this is that the ability to do that thing might
> only be desired within a certain scope.  Implicit conversions let you
> add the ability without making it available to code that doesn't
> import the conversion, and they work against objects not created by
> the code that requires that ability, e.g., Strings.
>

I think you make a good point here.

Mixin composition has a global effect, but I realize I have sometimes
mixed-in just to meet a local need.

>> Lets get specific. The use-case the started this off was a desire to
>> define a specialized form of ordering over homogeneous containers of
>> ordered items (basically, vectors).
>
> See Ordering in 2.8.

I dont think the dominance concept I described is a total ordering, as
required by Ordering. For example
(1,2) all_> (2,1) == false
(1, 2) all_< (2, 1) == false
((1, 2) == (2, 1)) == false

-Ben