Hi all,

While trying to convert Haskell statements like this to Perl 6:

 data Cxt = CxtVoid         -- ^ Context that isn't expecting any values
          | CxtItem !Type   -- ^ Context expecting a value of the specified type
          | CxtSlurpy !Type -- ^ Context expecting multiple values of the
                            --     specified type
     deriving (Eq, Show, Ord)

I'd like to be able to write it something like this:

 type Cxt is CxtVoid
           | CxtItem of Type
           | CxtSlurpy of Type
      does (Eq, Show, Ord);

To be a shorthand for:

 type CxtVoid;
 type CxtItem of Type;
 type CxtSlurpy of Type;
 type Perl::Cxt is CxtVoid | CxtItem | CxtSlurpy
    does Eq does Show does Ord;

Is this overloading the 'of' operator too far?

For many there will be a lot of new concepts there. For a start, I'm assuming that "of" is being used as a higher order type definition, much like "Array of Wotsits" would declare. Also, there is a type there - CxtVoid - which is nothing but a Type! No representation. Of course, if you have a variable of type Cxt, and it is a CxtVoid, then that will need to be represented in some way. But you generally wouldn't care how.

An alternative might be to try to shoe-horn the concepts into Roles etc.  Who 
knows, perhaps they'll even fit!  :-)


Reply via email to