The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Perlude - an attempt to port a part of Haskell prelude in Perl

SYNOPSIS

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

FUNCTIONS

relations between the computation world and perl

enlist

enlist transform a coderef to a lazy list.

    my $nat = enlist { state $x = 0; $x++ }

$nat is a lazy list of the naturals.

fold

consume a lazy list in an array

    my @top10nat =
        fold take 10,
        enlist { state $x=0; $x++ }

unfold

the conterpart of fold

take

take the n first elements of a lazy list

takeWhile

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++ }

drop, dropWhile

like take and takeWhile but remove elements instead of returning them

filter, apply

grep and map alike on lazy lists

    sub double { apply  { $_*2 } shift }
    sub evens  { filter { ($_ % 2) == 0 } shift }

traverse

eval the block for every element of the list.

    traverse {say} take 10, unfold 0..13;

concat

bind lazy list together.

    traverse {say} take 10, concat
    ( unfold(1..5)
    , unfold(20..67)
    );

misc. functions

definitely need other namespaces for them!

    cycle range tuple lines

missing functions

    foldl foldr

AUTHORS

  • Philippe Bruhat (BooK)

  • Marc Chantreux (eiro)

  • Olivier Mengué (dolmen)

ACKNOWLEDGMENTS

  • 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