Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-20 09:38:36

Brian McNamara <lorgon_at_[hidden]> writes:

> Is it possible to use tuple/variant to define recursive algebraic
> datatypes? In Haskell I might say something like
> type Operand = String -- e.g. "+" or "<<"
> data ExprTreeNode = ETN Operand ExprTree ExprTree
> data ExprTreeLeaf = ETL Int
> type ExprTree = Either ExprTreeLeaf ExprTreeNode
> If I try to translate this directly into C++, I might say
> typedef std::string Operand;
> typedef tuple<Operand,ExprTree*,ExprTree*> ExprTreeNode;
> typedef int ExprTreeLeaf;
> typedef variant<ExprTreeLeaf,ExprTreeNode> ExprTree;
> except that this doesn't work, since we need to somehow forward-declare
> that ExprTree is a typename or something.
> Is there any way to do this? Is there a good way to do this?

Isn't this very close to what you're doing?

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at