When I was giving a talk at YAPC, someone asked me if a Haskell data type is like a blessed object in Perl. I said that they were profoundly different. Well, that was probably too offputting: a Haskell datatype can be represented as a Perl 6 Role, and its variants as different Classes.
To facilitate the Perl 6-on-Perl 6 efforts, Audrey asked me to write a general automatic DrIFT-based Hs->P6 converter. The first use is to put the new AST scheme in a language where data can be more readily manipulated. For example, here is a function parameter in both Haskell and Perl 6:
-- Haskell
data Param = MkParam
{ p_variable :: Ident
, p_types :: [Class]
, p_constraints :: [Code]
, p_unpacking :: Maybe Sig
, p_default :: Maybe Exp
, p_label :: Ident
, p_slots :: Table
, p_hasAccess :: ParamAccess
, p_isRef :: Bool
, p_isLazy :: Bool
}
# Perl 6
role Param is TaggedUnion;
class MkParam does Param {
has Ident $.p_variable;
has Class @.p_types;
has Code @.p_constraints;
has Sig $.p_unpacking;
has Exp $.p_default;
has Ident $.p_label;
has Table $.p_slots;
has ParamAccess $.p_hasAccess;
has Bool $.p_isRef;
has Bool $.p_isLazy;
};
Here is the latest AST translation (and where that came from). This is a step towards assuring that Pugs' Perl 6 AST can be shared by other implementations, and (for example) macros that manipulate parsed bits of Perl can work on more than one compiler.
So far this was much easier to do than our YAML class (that bridges why++'s libsyck with Haskell for any data). But the next step is figuring out how to dump actual arbitrary Perl 6 values...
Comments
You can follow this conversation by subscribing to the comment feed for this post.