Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: What will scientific computing in Perl 6 look like?

by moritz (Cardinal)
on Jul 14, 2008 at 12:22 UTC ( #697461=note: print w/replies, xml ) Need Help??

in reply to Re^2: What will scientific computing in Perl 6 look like?
in thread What will scientific computing in Perl 6 look like?

Complex numbers are special cased, in that they are explicitly specced. While numerics aren't a weak spot in Perl 6, they aren't exactly the most powerful area either (Larry keeps telling us on #perl6 that he doesn't do higher mathematics ;-)

But it's quite easy to define your own data types and the associated operations:

# suppose you inherit from List to implement your vector: class MyVector is List { sub infix:<+>(MyVector @self, MyVector @other) is export { return @self + @other; } # adding a scalar: sub infix:<+>(MyVector @self, Num $other) is export { return @self + $other } }

No more hassle of overloading literal constants in the source, since multi method dispatch takes care of it all.

Replies are listed 'Best First'.
Re^4: What will scientific computing in Perl 6 look like?
by tilly (Archbishop) on Jul 15, 2008 at 00:32 UTC
    I simply don't believe that multi method dispatch takes care of it all when it comes to different number systems. While Perl 6 offers a lot of features, to the best of my knowledge The Structure of Computer Programming is still correct when it says "Developing a useful, general framework for expressing the relations among different types of entities (what philosophers call ``ontology'') seems intractably difficult. The main difference between the confusion that existed ten years ago and the confusion that exists now is that now a variety of inadequate ontological theories have been embodied in a plethora of correspondingly inadequate programming languages. For example, much of the complexity of object-oriented programming languages -- and the subtle and confusing differences among contemporary object-oriented languages -- centers on the treatment of generic operations on interrelated types."

    That is not to say that Perl 6 is not an improvement. It is. It just isn't a solution.

      Well, Perl 6's type system has difficulties with respect to numeric types, because they don't form a nice hierarchy. Luckily we have roles, and thus can have a type of all (scalar) numeric types without pressing them into a hierarchy.

      Implementing the numeric types correctly is a bit tricky, but the fact remains that the user (aka Perl 6 programmer) can simply add (or override) operators for each pair of types. If one of them is always a user-defined one you can guarantee no clashes with existing semantics.

      So I don't see how Perl 6 isn't a solution wrt to adding new numeric types to the language - would you care to elaborate?

        I believe the book's qualms about calling that a solution involve the possibility of a combinatorial explosion if the language forces you do define all possible pairings, and the opacity and artificial stupidity of the solution if the computer is attempting to use artificial intelligence to second-guess the programmer's ideas of what should be intuited when types are not arrangeable in a simple "tower".

        Of course, this does not stop us from trying to solve the problem anyway... :)

Re^4: What will scientific computing in Perl 6 look like?
by John M. Dlugosz (Monsignor) on Jul 15, 2008 at 06:21 UTC
    Don't you need to use the multi keyword on those subs?
      It's better style, but if the prelude defines a proto infix:<+> (and I'm quite sure it does) it's redundant. Good catch anyway.
        Ah yes, I remember that now. One motivation behind proto was that, so existing code included after it would not cause conflicts but become multis (and the proto standardizes the argument matching).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://697461]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-05-24 20:11 GMT
Find Nodes?
    Voting Booth?