Perlude - an attempt to port a part of Haskell prelude in Perl
Haskell prelude miss you when you write perl stuff? Perlude is a port of the most common keywords. Some other keywords where added when there is no haskell equivalent.
Example: in haskell you can write
nat = [0..] is_even x = ( x `mod` 2 ) == 0 evens = filter is_even main = mapM_ print $ take 10 $ evens nat
in perlude, the same code will be:
use Perlude; my $nat = enlist { state $x = 0; $x++ }; sub is_even { ($_ % 2) == 0 } sub evens { filter {is_even} shift } traverse {say} take 10, evens $nat
enlist transform a coderef to a lazy list.
my $nat = enlist { state $x = 0; $x++ }
$nat is a lazy list of the naturals.
consume a lazy list in an array
my @top10nat = fold take 10, enlist { state $x=0; $x++ }
the conterpart of fold
take the n first elements of a lazy list
returns the head of a lazy list that matches a crteria.
sub below { takeWhile { $_ < 1000 } shift } say for fold below 1000, enlist { state $x=0; $x++ }
like take and takeWhile but remove elements instead of returning them
grep and map alike on lazy lists
sub double { apply { $_*2 } shift } sub evens { filter { ($_ % 2) == 0 } shift }
eval the block for every element of the list.
traverse {say} take 10, unfold 0..13;
bind lazy list together.
traverse {say} take 10, concat ( unfold(1..5) , unfold(20..67) );
definitely need other namespaces for them!
cycle range tuple lines
foldl foldr
Philippe Bruhat (BooK)
Marc Chantreux (eiro)
Olivier Mengué (dolmen)
High five with Stéphane Payrard (cognominal) and thanks to Nicolas Pouillard (#haskell-fr@freenode) for his help about haskell lazyness.
French Perl Workshop 2011
Chartreuse Verte
To install Perlude, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perlude
CPAN shell
perl -MCPAN -e shell install Perlude
For more information on module installation, please visit the detailed CPAN module installation guide.