Upgrade to Pro — share decks privately, control downloads, hide ads and more …

functional Perl 6

lichtkind
September 04, 2015

functional Perl 6

important functional features Haskell has, that are supported by Perl 6 too and the cultural differences between Perl and functional

lichtkind

September 04, 2015
Tweet

More Decks by lichtkind

Other Decks in Programming

Transcript

  1. func. programming What is it? What is it good for?

    How much can P6? How it's done in P6?
  2. Features: parameter, functions, HOP (abstract) types, -classes, -inferenz lists-, comprehension,

    generators, tuple, currying,folding,map,filter pattern matching (MMD)
  3. Functional: old school (58): LIS P , S c h

    e m e , λc alc ulus new school (70's): ML, Ocaml, Haskell
  4. Multi Method Dispatch multi sub ask (Num $p){ multi sub

    ask (Str $p){ ask (“what now?”);
  5. for @l Z @m Z @r -> $l, $m, $r

    { ... parallel processing
  6. Function in P6 m e t a o b j

    e c t k n o w s : n r . & ( s u b - ) t y p e s o f p a r a m e t e r a n d r e t u r n v a l u e s
  7. #associativity left my $sum = [ + ] @rray; #

    (((..+..) + ..) + ..) foldl / foldr
  8. f o l d l : : ( a -

    > b - > a ) - > a - > [ b ] - > a f o l d l f z [ ] = z f o l d l f z ( x : x s ) = f o l d l f ( f z x ) x s foldl
  9. sub add (Int $a, Int $b --> Int) {$a +

    $b}; sub foldl( &f:(Int, Int --> Int ), Int $sum, List:Int $l --> Int) { if $l.elems > 0 { my Int $first = shift $l; foldl(&f, &f($sum, $first), $l)} else {$sum} }; say foldl(&add, 0, [1..4]); foldl in P6
  10. #associativity left my $sum = [ + ] @rray; #

    (((..+..) + ..) + ..) foldl / foldr
  11. @age == 18, 22, 35; @age = @age >>+>> 1;

    @age == 19, 23, 36; all age
  12. <18, 22, 35> >>+<< <1, 2> ERROR <18, 22, 35>

    <<+>> <1, 2> 19, 24, 36 interesting cases
  13. Currying f : X x Y --> Z ==> f

    : X --> ( Y --> Z )