Functional Logo Perl                  
history | edit

Functional programming on Perl (5)

This project aims to provide modules as well as tutorials and introductionary materials and other knowledge to work in a functional style on Perl. Currently the focus is on getting it to work well for programs on Perl 5. We'd appreciate discussing and collaborating with people working on Perl 6 now already, though, so as to adapt where useful.

Contents

  • 1. Teaser
  • 2. Status: experimental
  • 3. Parts
  • 4. Documentation
  • 5. Dependencies
  • 6. Installation
  • 1. Teaser

    This is an example of the kind of code we want to make possible:

    use PXML::Tags qw(myexample protocol-version records record a b c d);
    
    print RECORD(A("hi"),B("there"))->string; 
    # prints: <record><a>hi</a><b>there</b></record>
    
    # Now create a bigger document, with its inner parts built from
    # external inputs:
    MYEXAMPLE
      (PROTOCOL_VERSION ("0.123"),
       RECORDS
       (csv_file_to_rows($inpath, {eol=> "\n", sep_char=> ";"})
        # skip the header row
        ->rest
        # map rows to XML elements
        ->map(sub {
                  my ($a,$b,$c,$d)= @{$_[0]};
                  RECORD A($a), B($b), C($c), D($d)
              })))
      # print data structure to disk, forcing its evaluation as needed
      ->xmlfile($outpath);
    
    # Note that the above document is built lazily: `csv_file_to_rows`
    # returns a *lazy* list of rows, which means the rows will only be
    # read from disk once `xmlfile` runs and requests each
    # XML-formatted row in turn while it prints the document as a
    # string to the out file.
    

    See examples/csv_to_xml_short for the complete script, and the examples page for more.

    The above example shows the use of functions as "template system", and lazy sequences. They are also internally implemented using the functional paradigm.

    Note that the example assumes that steps have been taken so that the CSV file doesn't change until the serialization step has completed, otherwise functional purity is broken; functional-perl, like in most functional languages (Scheme, Clojure, lazy streams on Perl 6, ..) that don't take type guarantees to the extreme (e.g. Haskell), the responsibility to ensure this assumption is left to the programmer (see howto (Pure functions versus I/O an..) for more details about this).

    If you'd like to see a practical step-by-step introduction, read the intro.

    2. Status: experimental

    There are several reasons that this project should be considered experimental at this time:

    The plan is to accept compatibility-breaking changes until February 2016, then make a stable release in April 2016. If you'd like to get a maintained and versioned release earlier, please say so.

    I'm using it already in personal projects; where breakage due to changes is unacceptable, I currently add functional-perl as a Git submodule to the project using it and use lib it from the actual project.

    3. Parts

    4. Documentation

    It probably makes sense to look through the docs roughly in the given order, but if you can't follow the presentation, skip to the intro, likewise if you're bored skip ahead to the examples and the howto/design documents.

    Please ask me or on the mailing list if you'd like to meet up in London or Switzerland to get an introduction in person.

    5. Dependencies

    (Todo: should all of the above be listed in PREREQ_PM in Makefile.PL?)

    6. Installation

    git clone https://github.com/pflanze/functional-perl.git
    cd functional-perl
    
    # to get the latest release, which is 2 commits behind master:
    git checkout -b v0_665 v0.665
    
    # to verify the same against MitM attacks:
    gpg --recv-key 04EDB072
    git tag -v v0.665
    # You'll find various pages in search engines with my fingerprint,
    # or you may find a trust chain through one of the signatures on my
    # older key 1FE692DA, that this one is signed with.
    

    The bundled scripts modify the library load path to find the files locally, thus no installation is necessary. All modules are in the lib/ directory, export PERL5LIB=path/to/functional-perl/lib is all that's needed.

    The normal perl Makefile.PL; make test && make install process should work as well. The repository is probably going to be split into or will produce several separate CPAN packages in the future, thus don't rely on the installation process working the way it is right now.