|
Boost : |
From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-06-11 17:43:04
"Esa Pulkkinen" <esa.pulkkinen_at_[hidden]> wrote in message
news:200206111802.g5BI2YT06869_at_smtp2.sooninternet.net...
> Also, the visitor pattern is actually exactly the same as 'fold' is in
> functional languages, which is very closely related to unions. The
> corresponding inverse operation ("unfold") is also something I think
> should be remembered [a way to think of it is that 'visitor' (fold)
> reads (or destroys if you believe in functional languages) information
> from a data structure based on an algorithm and the unfold will
> construct such data structure based on an algorithm.]. In particular,
> using a visitor in conjunction with an 'unfold' operation will allow you
> to translate between any two variant data structures that have
> isomorphic structure.
That's indeed true (and cool). The corresponding version of "unfold" when
translated in industrialish/pattern lingo, is Factory. That is, you create
discriminated unions using a factory, and you uncloak their type by
visiting.
I wanted to write more about the connection between factories and
discriminated unions in my last installment treating Variant, but there was
no space. Anyway, the third and last article on Variant, together with
complete source code, will be soon available from
http://cuj.com/experts/2008/alexandr.htm.
Andrei
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk