On Tue, Nov 19, 2013 at 11:31 PM, Timon Gehr <[email protected]> wrote:

>
> In essence, the following is easily possible in theory:
>
> mixin ADT!q{
>  List(T):
>  | Nil
>  | Cons T List!T
> };
>
> auto list(R)(R r) if(isInputRange!R){
>     if(r.empty) return Nil!(ElementType!R);
>     auto f = r.front;
>     r.popFront();
>     return Cons(f,list(r));
> }
>
> size_t length(T)(List!T l){
>     return l.match!(
>         ()=>0,
>         (x,xs)=>1+length(xs)
>     );
> }

I concur, I did it also a few years ago. IIRC, I created an abstract
base class (List) and different subtypes. The associated matching
function was also generated at the same time.

What did you use to encode the types in your case? A tagged union?

Reply via email to