FAST

 view release on metacpan or  search on metacpan

lib/FAST/List/Gen/Haskell.pm  view on Meta::CPAN

package FAST::List::Gen::Haskell;
    use strict;
    use warnings;
    use lib '../../';
    use FAST::List::Gen::Lazy '*';
    use Scalar::Util 'weaken';
    sub DEBUG () {0}
    our @EXPORT = qw (lazy L lazyx Lx fn now seq map_ unzip unzipn x_xs);
    our @EXPORT_OK;
    my $setup_export = sub {
        @EXPORT_OK = keys %{{map {$_ => 1} @EXPORT, @FAST::List::Gen::EXPORT_OK}}
    };
    our %EXPORT_TAGS = (base => \@EXPORT, all => \@EXPORT_OK);
    BEGIN {
        no strict 'refs';
        *import  = *FAST::List::Gen::import;
        *{uc $_} = *{'FAST::List::Gen::'.uc} for 'version'
    }
    our ($a, $b);
    no if ($] > 5.012), warnings => 'illegalproto';


=head1 NAME

FAST::List::Gen::Haskell - the haskell prelude in perl5

=head1 SYNOPSIS

this module provides most of the functions in the haskell prelude that pertain
to working with lists.

    # haskell:  fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

    use FAST::List::Gen::Haskell;

    $fibs = lazy 0, 1, zipWith {&sum} $fibs, tail $fibs;

    print "@$fibs[0 .. 10]\n"; # prints '0 1 1 2 3 5 8 13 21 34 55'

C< lazy > provides the generic behavior of haskell's lazy list concatenation
(the C< : > and C< ++ > operators). none of its elements are touched until they
are needed. in general, all the functions in this package defer their execution
until something is required of them.  they also only touch their arguments at
the latest possible time, which is how the co-recursion above works.

the functions in this module are a bit more flexible (perlish) than those in
haskell.  in most cases where a function expects a single generator, a list of
values and/or generators can be provided, which will be preprocessed by
C< lazy > into a single generator.

when loaded, most of the functions in this package become methods for all
generators. if a method of the same name already exists, the method from this
package will be prefixed with C< hs_ >. so C< filter > is a method named
C<< ->hs_filter(...) >>

this library currently does not have the best performance due to over-caching
of many internal generators.  a future update will address this by replacing
those generators with cache-less generator streams.

=cut

    sub let {
        my ($name, $code) = splice @_, 0, 2;

        $_ = &fn (ref eq 'ARRAY' ? @$_ : $_, @_) for $code;



( run in 1.788 second using v1.01-cache-2.11-cpan-39bf76dae61 )