develooper Front page | perl.perl6.language | Postings from July 2005

Type::Class::Haskell does Role

Thread Next
Yuval Kogman
July 14, 2005 16:38
Type::Class::Haskell does Role
Message ID:
Haskell has this very nice consistency.... I'll diverge into perl

The 'Show' role provides consistent stringification semantics for
any type that does the role. It can even 'derive' the role, getting
a method autogenerated.

The 'Ord' role provides semantics for ordered types. A typical
structure that uses this is the map - it is a sorted collection of
stuff, and the key must do the 'Ord' role.

And so on and so forth.

Meanwhile in perl 5 land we have:

	* eq vs ==
	* stringifying objects is rarely meaningful
	* there isn't a culture of "functional programming" like reuse -
	  we do it on an entirely different level.

Can this fit into perl 6?

As I see it == is the generic comparison, and 'eq' is == with
coercing parameters (in Haskell it'd be
eq :: (Show a) => a -> a -> Bool or so... Isn't that lovely?)

Anywho, my point is - there's lots we can borrow to make our prettier, and our code a little more generic.

Mechanical conversion from perl 5 can use the fully qualified
instances of '==' and 'eq' in the Str and Num roles.

 ()  Yuval Kogman <> 0xEBD27418  perl hacker &
 /\  kung foo master: /me beats up some cheese: neeyah!!!!!!!!!!!!!!!!!

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About