Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing functional programming in Perl

I am trying to learn pure functional programming language like Haskell as I am from Perl background and read that Perl can also implement functional programming techniques. So few questions came in mind:

  • Whether it is worth doing it in Perl 5?
  • Does Perl 6 will make a difference?
  • Can anybody suggest some code/examples implementing functional programming techniques in Perl?
  • like image 570
    ppant Avatar asked Oct 29 '10 07:10

    ppant


    People also ask

    Is Perl a functional programming language?

    Perl is not a functional language in the sense that it also uses several other programming paradigms that we have seen abundantly throughout this book.

    What do you mean by functional programming?

    1) Functional programming is a style of programming that emphasizes the evaluation of expressions rather than the execution of commands. Erlang programming language is described as a functional programming language.


    3 Answers

    Read Higher-Order Perl. You can buy it or download for free. It provides insights even to experienced Perl programmers.

    like image 53
    musiKk Avatar answered Sep 17 '22 22:09

    musiKk


    perl6 is still a work in progress, so even though perl6 has much improved support for functional programming at the language level (see perlgeek.de on currying in perl6, for example), you'll probably want to start now with perl5 so you can get to work with what's out there. i recommend looking into cpan for higher-level library support...Array::Utils and others (there's a lot!)

    like image 26
    Brad Clawsie Avatar answered Sep 17 '22 22:09

    Brad Clawsie


    Functional programming is just programming, you can do it in any language. If you like how the Haskell API is laid out, you might like my Data::Monad module, which provides Moose roles for various Haskell typeclasses including Monad. (Unlike Haskell, though, there is no "fail" in my Monad, and all Monads are Functors.)

    Here's an example of exercising the various typeclasses in the context of a data structure that handles success or failure (like Control.Monad.Error):

    http://github.com/jrockway/data-monad/blob/master/t/error.t

    Note that it has the ability to convert usual Perl computations that can fail with an exception to a pure procedure that you can bind to other procedures. This lets "regular Perl" work inside a program designed to have a more functional control flow.

    like image 38
    jrockway Avatar answered Sep 18 '22 22:09

    jrockway