Hi Philippe,

Philippe (>):
> will Abstract Data Types and Generalized Abstract Data Types be available in 
> Perl6 anytime soon?

Algebraic Data Types -- this is a topic that has come up before on
#perl6 on IRC. Often enough I've been the one mentioning it. Let's
just stop briefly to define a few things that we may associate with
ADTs.

As an example, I'll throw up this classic ADT from Haskell:

  data Tree a = Branch (Tree a) (Tree a) | Leaf a

Now, let's list what this gives us:

(a) Nice syntax for (recursively) specifying the type.
(b) Nice syntax for constructing values of the type.

Not shown above, but equally important in my view, are the consumption
end of ADTs:

(c) Nice destructuring syntax when matching against a value.
(d) Ease of binding the matched bits to variables and using those.

Just for fun, I put together two ways to emulate ADTs in Perl 6. These
two gists both run in Rakudo today.

Using hashes and subclasses: <https://gist.github.com/masak/5213423>
Using classes and subclasses: <https://gist.github.com/masak/5213563>

I'd say the first solution does OK at (a), but it's not excellent and
definitely contains boilerplate, especially in those subs. It does (b)
OK, but only because things are very lax. It only begins to do (c) --
it doesn't look into the values -- and it doesn't really do (d) at
all.

In comparison, the second solution is a bit stricter with (b), in
exchange for having a bit more boilerplate in (a). (c) and (d) are
equally bad as in the first solution.

Furthermore, what I'd really like to see is compiler support for all
those four things -- basically type checking on ADTs at compile-time.
People on #perl6 started talking about macros and how they would help
here. I think that's a viable approach, but just how far it gets us
remains to be seen.

As to GADTs, I fear I don't understand them well enough to give a good
answer there. But generally, Perl 6 doesn't do as much typechecking at
compile time as would a strict language, so they may or may not be as
feasible, or even as necessary. People who grok type theory better may
be able to tell you more there, though.

// Carl

Reply via email to