SlideShare une entreprise Scribd logo
1  sur  54
Arrows in Perl
2011.12.10 hiratara
d.hatena.ne.jp/hiratara

twitter.com/hiratara



Perl
d.hatena.ne.jp/hiratara

twitter.com/hiratara



Perl
Perl

Haskell
Perl

Haskell
Perl

Haskell
Perl

Haskell
10/18 YAPC::Asia 2011

Monads in Perl
  Perl Monad

  Future
  (        JSDeferred)
10/18 YAPC::Asia 2011

Monads in Perl
  Perl Monad

  Future
  (        JSDeferred)
10/18 YAPC::Asia 2011

Monads in Perl
  Perl Monad

  Future
  (        JSDeferred)
Data::Monad

my $result = Data::Monad::Base::Sugar::for {
    pick my $x => sub { scalar_list 1 .. 100 };
    pick my $y => sub { scalar_list $x .. 100 };
    pick my $z => sub {
     scalar_list $y .. ($x + $y > 100 ? 100 : $x + $y)
    };
    satisfy { $x**2 + $y**2 == $z**2 };
    yield { $x, $y, $z }
};
return    >>=

return :: a -> m a
>>= :: m a -> (a -> m b) -> m b
return               >>=
ma       mb         mb       mc        ma        mc

     f        >=>        g        ==     f >=> g
a         b         b        c         a        c

ma                  ma       mb        ma        mb
 return       >=>        f        ==         f
a                   a        b         a         b
(2)

                              2



     fmap                return   join

fmap :: a -> b -> (m a -> m b)
join :: m (m a) -> m a
(3)
η⊗id           id⊗η
I⊗M              M⊗M            M⊗I

                     μ
      λ                     ρ

                 M
(                 )
              0×id                   id×0
(*, n)               (0, n) (n, 0)              (n, *)

                              (+)
         π’                             π

                          n
(            )
       fmap return              return
id.fmap            fmap.fmap               fmap.id

                         join
       id                             id

                    fmap
(            )
       fmap return              return
id.fmap            fmap.fmap               fmap.id

                         join
       id                             id

                    fmap
Arrows

John Hughes   2000
Monad    Arrow


                 (Haskell    )
                                 mb

                             f
                         a
Arrows

                         f :: m b c   b
                     a
Arrows

arr >>> first                    ↝

arr :: a -> b -> (a ↝ b)

>>> :: (a ↝ b) -> (b ↝ c) -> (a ↝ c)

first :: (a ↝ b) -> (a × c ↝ b × c)
Arrow
        package Arrow;

        sub arr {
        	 my ($class, $code) = @_;
        	 die "not implemented";
        }

        sub first {
        	 my $self = shift;
        	 die "not implemented";
        }

        sub next {
        	 my ($self, $arrow) = @_;
        	 die "not implemented";
        }
first
     a↝b       a   b

     >>>

     arr           ↝


a          f   b           a      arr f :: a ↝ b
                                                    b

               g   arr   arr f >>> arr g :: a ↝ c
                                                        arr g :: b ↝ c

    g.f
               c                                    c
first
           Arrow ↝

           a                    c   a×c

f :: a↝b             g :: c↝d         f *** g :: a×c↝b×d




           b                    d   b×d
(f *** g) >>> (f’ *** g’)   (f >>> f’) *** (g >>> g’)


      f           g                f          g




       f’         g’               f’        g’
(f *** g) >>> (f’ *** g’)   (f >>> f’) *** (g >>> g’)


      f           g                f          g




       f’         g’               f’        g’
premonoidal category

 f ⋉ id = first f     a×b          a×b
 id ⋊ f = second f
                        f ⋉ id
                     a’×b            (f>>>f’) ⋉ id

                        f’ ⋉ id

                     a’’×b        a’’×b
premonoidal category

 f ⋉ id = first f     a×b          a×b
 id ⋊ f = second f
                        f ⋉ id
                     a’×b            (f>>>f’) ⋉ id

                        f’ ⋉ id

                     a’’×b        a’’×b
central

 f *** g ≡ first f >>> second g
 first f >>> second - = second - >>> first f
 first - >>> second f = second f >>> first -
           f central

 arr f   central

 f |x g ≡ first f >>> second (arr g)
 (                                     10.2)
Freyd category

                     premonoidal category


(central        central          )

           a -> b            Arrow a ↝ b
     arr              Freyd category
first   (   )
second              ***
 sub second {
 	 my $self = shift;
 	 my $swap = (ref $self)->arr(sub { $_[1], $_[0] });
 	 $swap->next($self->first)->next($swap);
 }



 sub parallel {
 	 my ($self, $arrow) = @_;
 	 $self->first->next($arrow->second);
 }

                     fst f >>> snd g
                       id        g
               C            C        D

                       f             id
               A              B            B
&&&
     sub split {
     	 my ($self, $arrow) = @_;
     	 (ref $self)->arr(sub {
     	 	 my $args = [@_];
     	 	 $args, $args;
     	 })->next($self->parallel($arrow));
     }

            A                                         A
                                                                  arr id
                                         arr id
                                                  arr <id, id>
     f                 g             A       arr π
                                                     A×A     arr π’
                                                                           A
            f &&&g               f                                             g
                                                          f *** g
                                             arr π               arr π’
B
    arr π
            B×C   arr π’
                           C         B               B×C                   C
(1):


Perl
f : A×B → C×D
(1):


first :: a × b × c -> d × e
 -> (a × b × c × y × z -> d × e × y × z)
                        5
(1):
 f                              (@v1 )
     sub first {
     	 my $self = shift;
     	 (ref $self)->arr(sub {
     	 	 my (@v1, @v2) = @_;
     	 	 $self->(@v1), @v2;
     	 });
     }




                 first              2
(A × B) × (C × D)
package Arrow::Subroutine;
use parent qw/Arrow/;

sub arr {
	 my ($class, $code) = @_;
	 bless $code, $class;
}

sub first {
	 my $self = shift;
	 (ref $self)->arr(sub {
	 	 my ($v1, $v2) = @_;
	 	 [$self->(@$v1)], $v2;
	 });
}

sub next {
	 my ($self, $arrow) = @_;
	 (ref $self)->arr(sub { $arrow->($self->(@_)) });
}
my $arr3 = Arrow::Subroutine->arr(sub { 3 });
my $arr4 = Arrow::Subroutine->arr(sub { 4 });
my $arrow_add = Arrow::Subroutine->arr(sub {
	 $_[0]->[0] + $_[1]->[0];
});
my $arr3_plus_4 = $arr3->split($arr4)->next($arrow_add);

print $arr3_plus_4->(), "n";


               3
                          π

         ()
               3 &&& 4               +
                         Int×Int             Int
                          π’
               4
(2):


              >>> arr

first
first
       a   π    a×c      π’    c


   f               f×return        return


           π              π’
   mb          mb×mc           mc
                  φ

               m(b×c)
package Arrow::Kleisli;
use parent qw/Arrow/;

sub _safe_name($) {
    my $name = shift;
    $name =~ s|::|__|g;
    return "__$name";
}

sub new_class {
    my $class = shift;
    my ($monad) = @_;

    my $class_name = "$class::" . _safe_name($monad);
    unless ($class_name->isa($class)) {
        no strict qw/refs/;
        @{"$class_name::ISA"} = ($class);
        *{"$class_name::monad"} = sub { $monad };
        *{"$class_name::new_class"} = sub {
            die "Don't call the new_class() method from sub classes.";
        };
    }

    return $class_name;
}

sub monad { die "Implement this method in sub classes" }
...
sub new {
	 my ($class, $kleisli) = @_;
	 bless $kleisli, $class;
}

sub arr {
	 my ($class, $code) = @_;
	 $class->new(sub {
	 	 $class->monad->unit($code->(@_));
	 });
}

sub next {
	 my ($self, $arrow) = @_;
	 (ref $self)->new(sub {
	 	 my @v = @_;
	 	 $self->(@v)->flat_map($arrow);
	 });
}
sub first {
	 my $self = shift;
	 my $class = (ref $self);
	 my $monad = $class->monad;

	   $class->new(sub {
	   	 my ($args1, $args2) = @_;
	   	 $monad->sequence(
	   	 	 $self->(@$args1)->map(sub {[@_]}),
	   	 	 $monad->unit(@$args2)->map(sub {[@_]}),
	   	 );
	   });
}
arr 10
                              arr π

     ()
          arr 10 &&& arr 2             div
                             Int×Int         Int
                              arr π’
            arr 2




div :: Int×Int ↝ Int = Int×Int → Maybe Int
my $class = Arrow::Kleisli->new_class('Data::Monad::Maybe');
my $arrow10 = $class->arr(sub { 10 });
my $arrow2 = $class->arr(sub { 2 });
my $arrow_div = $class->new(sub {
	 $_[1][0] == 0 ? nothing : just ($_[0][0] / $_[1][0]);
});
my $arrow10_div_2 = $arrow10->split($arrow2)-
>next($arrow_div);

my $maybe = $arrow10_div_2->();
print $maybe->is_nothing ? 'NOTHING' : $maybe->value;
print "n";
Arrows

Stream            Arrows
:
Arrows

 mm        join       return
                  m            id



           >>>         arr
 ↝⊗↝              ↝            Hom
(            )

            arr⊗id              id⊗arr
Hom⊗↝                ↝⊗↝                   ↝⊗Hom

                          >>>
        λ                              ρ

                      ↝
Arrows

first

LL       Arrows
http://d.hatena.ne.jp/m-hiyama/20111107/1320624410
Arrows in perl

Contenu connexe

Tendances

Python decorators
Python decoratorsPython decorators
Python decoratorsAlex Su
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Python decorators (中文)
Python decorators (中文)Python decorators (中文)
Python decorators (中文)Yiwei Chen
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionosfameron
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in PythonBen James
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиMaxim Kulsha
 
Pyimproved again
Pyimproved againPyimproved again
Pyimproved againrik0
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - BasicWei-Yuan Chang
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)James Titcumb
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)James Titcumb
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)James Titcumb
 

Tendances (20)

Python decorators
Python decoratorsPython decorators
Python decorators
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Python decorators (中文)
Python decorators (中文)Python decorators (中文)
Python decorators (中文)
 
Get on with Field API
Get on with Field APIGet on with Field API
Get on with Field API
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures edition
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in Python
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Pyimproved again
Pyimproved againPyimproved again
Pyimproved again
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Part 7
Part 7Part 7
Part 7
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
 

Similaire à Arrows in perl

循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHPpwmosquito
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)Roman Brovko
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기JangHyuk You
 
Functional perl
Functional perlFunctional perl
Functional perlErrorific
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЮрий Сыровецкий
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHPIan Barber
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language TriviaNikita Popov
 
AA Section 8-1
AA Section 8-1AA Section 8-1
AA Section 8-1Jimbo Lamb
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境とTakeshi Arabiki
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and outputKavithaK23
 

Similaire à Arrows in perl (18)

循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
Math::Category
Math::CategoryMath::Category
Math::Category
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
 
Sigma type
Sigma typeSigma type
Sigma type
 
13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)13 - Scala. Dependent pair type (Σ-type)
13 - Scala. Dependent pair type (Σ-type)
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
Functional perl
Functional perlFunctional perl
Functional perl
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
Key pat1 1-53
Key pat1 1-53Key pat1 1-53
Key pat1 1-53
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
AA Section 8-1
AA Section 8-1AA Section 8-1
AA Section 8-1
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and output
 

Plus de Masahiro Honma

レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)Masahiro Honma
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになるMasahiro Honma
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl languageMasahiro Honma
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopmMasahiro Honma
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzMasahiro Honma
 
モナモナ言うモナド入門
モナモナ言うモナド入門モナモナ言うモナド入門
モナモナ言うモナド入門Masahiro Honma
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LTMasahiro Honma
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGIMasahiro Honma
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGitMasahiro Honma
 
YAPCレポートの舞台裏
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏Masahiro Honma
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編Masahiro Honma
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編Masahiro Honma
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編Masahiro Honma
 

Plus de Masahiro Honma (20)

レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
 
Currying in perl
Currying in perlCurrying in perl
Currying in perl
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
 
モナモナ言うモナド入門
モナモナ言うモナド入門モナモナ言うモナド入門
モナモナ言うモナド入門
 
Perl saved a lady.
Perl saved a lady.Perl saved a lady.
Perl saved a lady.
 
Levenshtein Automata
Levenshtein AutomataLevenshtein Automata
Levenshtein Automata
 
20120526 hachioji.pm
20120526 hachioji.pm20120526 hachioji.pm
20120526 hachioji.pm
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGit
 
YAPCレポートの舞台裏
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏
 
Git入門
Git入門Git入門
Git入門
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
 
定理3
定理3定理3
定理3
 

Dernier

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Dernier (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Arrows in perl

  • 8.
  • 9. 10/18 YAPC::Asia 2011 Monads in Perl Perl Monad Future ( JSDeferred)
  • 10. 10/18 YAPC::Asia 2011 Monads in Perl Perl Monad Future ( JSDeferred)
  • 11. 10/18 YAPC::Asia 2011 Monads in Perl Perl Monad Future ( JSDeferred)
  • 12. Data::Monad my $result = Data::Monad::Base::Sugar::for { pick my $x => sub { scalar_list 1 .. 100 }; pick my $y => sub { scalar_list $x .. 100 }; pick my $z => sub { scalar_list $y .. ($x + $y > 100 ? 100 : $x + $y) }; satisfy { $x**2 + $y**2 == $z**2 }; yield { $x, $y, $z } };
  • 13. return >>= return :: a -> m a >>= :: m a -> (a -> m b) -> m b return >>=
  • 14. ma mb mb mc ma mc f >=> g == f >=> g a b b c a c ma ma mb ma mb return >=> f == f a a b a b
  • 15. (2) 2 fmap return join fmap :: a -> b -> (m a -> m b) join :: m (m a) -> m a
  • 16. (3)
  • 17. η⊗id id⊗η I⊗M M⊗M M⊗I μ λ ρ M
  • 18. ( ) 0×id id×0 (*, n) (0, n) (n, 0) (n, *) (+) π’ π n
  • 19. ( ) fmap return return id.fmap fmap.fmap fmap.id join id id fmap
  • 20. ( ) fmap return return id.fmap fmap.fmap fmap.id join id id fmap
  • 21.
  • 23. Monad Arrow (Haskell ) mb f a Arrows f :: m b c b a
  • 24. Arrows arr >>> first ↝ arr :: a -> b -> (a ↝ b) >>> :: (a ↝ b) -> (b ↝ c) -> (a ↝ c) first :: (a ↝ b) -> (a × c ↝ b × c)
  • 25. Arrow package Arrow; sub arr { my ($class, $code) = @_; die "not implemented"; } sub first { my $self = shift; die "not implemented"; } sub next { my ($self, $arrow) = @_; die "not implemented"; }
  • 26. first a↝b a b >>> arr ↝ a f b a arr f :: a ↝ b b g arr arr f >>> arr g :: a ↝ c arr g :: b ↝ c g.f c c
  • 27. first Arrow ↝ a c a×c f :: a↝b g :: c↝d f *** g :: a×c↝b×d b d b×d
  • 28. (f *** g) >>> (f’ *** g’) (f >>> f’) *** (g >>> g’) f g f g f’ g’ f’ g’
  • 29. (f *** g) >>> (f’ *** g’) (f >>> f’) *** (g >>> g’) f g f g f’ g’ f’ g’
  • 30. premonoidal category f ⋉ id = first f a×b a×b id ⋊ f = second f f ⋉ id a’×b (f>>>f’) ⋉ id f’ ⋉ id a’’×b a’’×b
  • 31. premonoidal category f ⋉ id = first f a×b a×b id ⋊ f = second f f ⋉ id a’×b (f>>>f’) ⋉ id f’ ⋉ id a’’×b a’’×b
  • 32. central f *** g ≡ first f >>> second g first f >>> second - = second - >>> first f first - >>> second f = second f >>> first - f central arr f central f |x g ≡ first f >>> second (arr g) ( 10.2)
  • 33. Freyd category premonoidal category (central central ) a -> b Arrow a ↝ b arr Freyd category
  • 34. first ( )
  • 35. second *** sub second { my $self = shift; my $swap = (ref $self)->arr(sub { $_[1], $_[0] }); $swap->next($self->first)->next($swap); } sub parallel { my ($self, $arrow) = @_; $self->first->next($arrow->second); } fst f >>> snd g id g C C D f id A B B
  • 36. &&& sub split { my ($self, $arrow) = @_; (ref $self)->arr(sub { my $args = [@_]; $args, $args; })->next($self->parallel($arrow)); } A A arr id arr id arr <id, id> f g A arr π A×A arr π’ A f &&&g f g f *** g arr π arr π’ B arr π B×C arr π’ C B B×C C
  • 37. (1): Perl f : A×B → C×D
  • 38. (1): first :: a × b × c -> d × e -> (a × b × c × y × z -> d × e × y × z) 5
  • 39. (1): f (@v1 ) sub first { my $self = shift; (ref $self)->arr(sub { my (@v1, @v2) = @_; $self->(@v1), @v2; }); } first 2 (A × B) × (C × D)
  • 40. package Arrow::Subroutine; use parent qw/Arrow/; sub arr { my ($class, $code) = @_; bless $code, $class; } sub first { my $self = shift; (ref $self)->arr(sub { my ($v1, $v2) = @_; [$self->(@$v1)], $v2; }); } sub next { my ($self, $arrow) = @_; (ref $self)->arr(sub { $arrow->($self->(@_)) }); }
  • 41. my $arr3 = Arrow::Subroutine->arr(sub { 3 }); my $arr4 = Arrow::Subroutine->arr(sub { 4 }); my $arrow_add = Arrow::Subroutine->arr(sub { $_[0]->[0] + $_[1]->[0]; }); my $arr3_plus_4 = $arr3->split($arr4)->next($arrow_add); print $arr3_plus_4->(), "n"; 3 π () 3 &&& 4 + Int×Int Int π’ 4
  • 42. (2): >>> arr first
  • 43. first a π a×c π’ c f f×return return π π’ mb mb×mc mc φ m(b×c)
  • 44. package Arrow::Kleisli; use parent qw/Arrow/; sub _safe_name($) { my $name = shift; $name =~ s|::|__|g; return "__$name"; } sub new_class { my $class = shift; my ($monad) = @_; my $class_name = "$class::" . _safe_name($monad); unless ($class_name->isa($class)) { no strict qw/refs/; @{"$class_name::ISA"} = ($class); *{"$class_name::monad"} = sub { $monad }; *{"$class_name::new_class"} = sub { die "Don't call the new_class() method from sub classes."; }; } return $class_name; } sub monad { die "Implement this method in sub classes" } ...
  • 45. sub new { my ($class, $kleisli) = @_; bless $kleisli, $class; } sub arr { my ($class, $code) = @_; $class->new(sub { $class->monad->unit($code->(@_)); }); } sub next { my ($self, $arrow) = @_; (ref $self)->new(sub { my @v = @_; $self->(@v)->flat_map($arrow); }); }
  • 46. sub first { my $self = shift; my $class = (ref $self); my $monad = $class->monad; $class->new(sub { my ($args1, $args2) = @_; $monad->sequence( $self->(@$args1)->map(sub {[@_]}), $monad->unit(@$args2)->map(sub {[@_]}), ); }); }
  • 47. arr 10 arr π () arr 10 &&& arr 2 div Int×Int Int arr π’ arr 2 div :: Int×Int ↝ Int = Int×Int → Maybe Int
  • 48. my $class = Arrow::Kleisli->new_class('Data::Monad::Maybe'); my $arrow10 = $class->arr(sub { 10 }); my $arrow2 = $class->arr(sub { 2 }); my $arrow_div = $class->new(sub { $_[1][0] == 0 ? nothing : just ($_[0][0] / $_[1][0]); }); my $arrow10_div_2 = $arrow10->split($arrow2)- >next($arrow_div); my $maybe = $arrow10_div_2->(); print $maybe->is_nothing ? 'NOTHING' : $maybe->value; print "n";
  • 49. Arrows Stream Arrows
  • 50. : Arrows mm join return m id >>> arr ↝⊗↝ ↝ Hom
  • 51. ( ) arr⊗id id⊗arr Hom⊗↝ ↝⊗↝ ↝⊗Hom >>> λ ρ ↝

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. &amp;#x3010;5&amp;#x5206;&amp;#x3011;\n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. &amp;#x3010;10&amp;#x5206;&amp;#x3011;\n
  25. \n
  26. &amp;#x9EC4;&amp;#x8272;&amp;#x306E;&amp;#x90E8;&amp;#x5206;&amp;#x304C;&amp;#x95A2;&amp;#x6570;&amp;#x3067;&amp;#x306F;&amp;#x306A;&amp;#x304F;&amp;#x578B;&amp;#x306A;&amp;#x306E;&amp;#x304C;&amp;#x30DD;&amp;#x30A4;&amp;#x30F3;&amp;#x30C8;&amp;#x3002;\n
  27. \n
  28. \n
  29. &amp;#x7D50;&amp;#x5408;&amp;#x5247;&amp;#x3092;&amp;#x6E80;&amp;#x305F;&amp;#x3059;&amp;#x3088;&amp;#x3046;&amp;#x306A;&amp;#x5B9A;&amp;#x7FA9;&amp;#x3092;&amp;#x3057;&amp;#x3066;&amp;#x304A;&amp;#x3044;&amp;#x305F;&amp;#x65B9;&amp;#x304C;&amp;#x53B3;&amp;#x5BC6;&amp;#x3060;&amp;#x3057;&amp;#x4F7F;&amp;#x3044;&amp;#x3084;&amp;#x3059;&amp;#x3044;\n
  30. \n
  31. &amp;#x3010;15&amp;#x5206;&amp;#x3011;\n
  32. \n
  33. &amp;#x4EFB;&amp;#x610F;&amp;#x306E;&amp;#x30A2;&amp;#x30ED;&amp;#x30FC;&amp;#x306B;&amp;#x5BFE;&amp;#x3057;&amp;#x3066;&amp;#x540C;&amp;#x3058;&amp;#x5B9F;&amp;#x88C5;&amp;#x304C;&amp;#x5229;&amp;#x7528;&amp;#x53EF;&amp;#x80FD;&amp;#x3002;&amp;#x62BD;&amp;#x8C61;&amp;#x5316;&amp;#x306E;&amp;#x52B9;&amp;#x529B;&amp;#x3002;\n
  34. &amp;#x4EFB;&amp;#x610F;&amp;#x306E;&amp;#x30A2;&amp;#x30ED;&amp;#x30FC;&amp;#x306B;&amp;#x5BFE;&amp;#x3057;&amp;#x3066;&amp;#x540C;&amp;#x3058;&amp;#x5B9F;&amp;#x88C5;&amp;#x304C;&amp;#x5229;&amp;#x7528;&amp;#x53EF;&amp;#x80FD;&amp;#x3002;&amp;#x62BD;&amp;#x8C61;&amp;#x5316;&amp;#x306E;&amp;#x52B9;&amp;#x529B;&amp;#x3002;\n
  35. \n
  36. \n
  37. \n
  38. &amp;#x3010;20&amp;#x5206;&amp;#x3011;\n
  39. \n
  40. \n
  41. \n
  42. &amp;#x30E2;&amp;#x30CA;&amp;#x30C9;&amp;#x3092;&amp;#x578B;&amp;#x30D1;&amp;#x30E9;&amp;#x30E1;&amp;#x30FC;&amp;#x30BF;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x6271;&amp;#x3046;&amp;#x305F;&amp;#x3081;&amp;#x306E;&amp;#x304A;&amp;#x307E;&amp;#x3058;&amp;#x306A;&amp;#x3044;\n
  43. return&amp;#x3084;bind&amp;#x3092;arrow&amp;#x306E;&amp;#x8A00;&amp;#x8449;&amp;#x306B;&amp;#x7FFB;&amp;#x8A33;&amp;#x3057;&amp;#x3066;&amp;#x308B;&amp;#x3060;&amp;#x3051;\n
  44. &amp;#x3055;&amp;#x3063;&amp;#x304D;&amp;#x306E;&amp;#x56F3;&amp;#x3092;&amp;#x5143;&amp;#x306B;&amp;#x5B9F;&amp;#x88C5;&amp;#x3002;map&amp;#x306E;&amp;#x8FBA;&amp;#x308A;&amp;#x306F;&amp;#x578B;&amp;#x3092;&amp;#x305D;&amp;#x308D;&amp;#x3048;&amp;#x308B;&amp;#x304A;&amp;#x307E;&amp;#x3058;&amp;#x306A;&amp;#x3044;\n
  45. &amp;#x3010;25&amp;#x5206;&amp;#x3011;&amp;#x3088;&amp;#x304F;&amp;#x3042;&amp;#x308B;0&amp;#x9664;&amp;#x7B97;&amp;#x306E;&amp;#x4F8B;\n
  46. &amp;#x3088;&amp;#x304F;&amp;#x3042;&amp;#x308B;0&amp;#x9664;&amp;#x7B97;&amp;#x306E;&amp;#x4F8B;\n
  47. \n
  48. &amp;#x4E0A;&amp;#x306F;&amp;#x81EA;&amp;#x5DF1;&amp;#x95A2;&amp;#x624B;&amp;#x570F;&amp;#x3002;&amp;#x4E0B;&amp;#x306F;Profunctor&amp;#x306E;&amp;#x570F;&amp;#x3002;&amp;#x4E0B;&amp;#x306E;&amp;#x65B9;&amp;#x304C;&amp;#x9065;&amp;#x304B;&amp;#x306B;&amp;#x96E3;&amp;#x3057;&amp;#x304F;&amp;#x3066;&amp;#x3088;&amp;#x304F;&amp;#x308F;&amp;#x304B;&amp;#x3089;&amp;#x306A;&amp;#x3044;&amp;#x3002;&amp;#x7279;&amp;#x306B; &amp;#x2297;&amp;#x306E;&amp;#x5B9A;&amp;#x7FA9;\n
  49. \n
  50. \n
  51. \n
  52. \n