[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?
Larry Evans
cppljevans at suddenlink.net
Sun Nov 30 13:49:29 EST 2008
On 11/30/08 12:27, Luke Palmer wrote:
> On Sun, Nov 30, 2008 at 11:04 AM, Larry Evans <cppljevans at suddenlink.net> wrote:
>> The following post:
>>
>> http://thread.gmane.org/gmane.comp.lib.boost.devel/182797
>>
>> shows at least one person that would find it useful, at least in
>> c++. Of course maybe it would be less useful in haskell.
>
> The line:
>
> typedef boost::mpl::vector <T1Variants, T2Variants, T3Variants> TT;
>
> Has the number of lists hard-coded as 3, and does not abstract over
> it. This corresponds to the "3" in "liftA3", or the number of <*>s in
> the expression.
>
> Abstracting over the number and types of arguments is something
> neither C++ nor Haskell is very good at. But in order to be able to
> do any abstraction using such a variable-argument function, the type
> systems of these languages would have to increase in complexity by
> quite a lot.
>
> Luke
True, but if you look at the cross_nproduct_view template:
{--cut here--
template
< class Domains
>
struct
cross_nproduct_view
: fold
< Domains
, cross_product_one
, cross_product_view<arg<2>,arg<1> >
>::type
{
};
}--cut here--
You'll see Domains can be an mpl::vector of any
length. The cross_nproduct_view_test.cpp tests
with a 3 element Domains:
typedef
mpl::vector
< mpl::range_c<int,0,4>
, mpl::range_c<int,100,103>
, mpl::range_c<int,2000,2002>
>
domains;
The cross_nproduct_view template and test driver
are found in the cross_nproduct_view.zip file here:
http://preview.tinyurl.com/5ar9g4
More information about the Haskell-Cafe
mailing list