e l a g é n o r h y n q u e [ K e n t O H A S H I ] : g i t h u b / t w i t t e r @ l a g e n o r h y n q u e : c o m p a n y 株式会社オプト : l a n g u a g e s [ C l o j u r e H a s k e l l P y t h o n S c a l a G o E n g l i s h f r a n ç a i s D e u t s c h р у с с к и й ] : i n t e r e s t s [ プログラミング 語学 数学] )
y t h o n d e f f i b o n a c c i ( i ) : a , b = 0 , 1 f o r n i n r a n g e ( i ) : a , b = b , a + b r e t u r n a 副作用( ) 命令型( ) side e ect imperative
- - H a s k e l l f i b o n a c c i 1 : : I n t - > I n t e g e r f i b o n a c c i 1 0 = 0 f i b o n a c c i 1 1 = 1 f i b o n a c c i 1 i = f i b o n a c c i 1 ( i - 2 ) + f i b o n a c c i 1 ( i - 1 ) ; ; C l o j u r e ( d e f n f i b o n a c c i 1 [ i ] ( c o n d ( = i 0 ) 0 N ( = i 1 ) 1 N : e l s e ( + ( f i b o n a c c i 1 ( - i 2 ) ) ( f i b o n a c c i 1 ( - i 1 ) ) ) ) ) パター ンマッチング( ) 宣言型( ) 参照透過性( ) pattern matching declarative referential transparency
a s k e l l f i b o n a c c i 2 : : I n t - > I n t e g e r f i b o n a c c i 2 i = f i b i 0 1 w h e r e f i b 0 a _ = a f i b n a b = f i b ( n - 1 ) b ( a + b ) ; ; C l o j u r e ( d e f n f i b o n a c c i 2 [ i ] ( l e t f n [ ( f i b [ n a b ] ( i f ( z e r o ? n ) a ( r e c u r ( d e c n ) b ( + a b ) ) ) ) ] ( f i b i 0 N 1 N ) ) )
H a s k e l l f i b o n a c c i 3 : : I n t - > I n t e g e r f i b o n a c c i 3 i = f s t $ f o l d l ' f i b ( 0 , 1 ) [ 1 . . i ] w h e r e f i b ( a , b ) _ = ( b , a + b ) ; ; C l o j u r e ( d e f n f i b o n a c c i 3 [ i ] ( l e t f n [ ( f i b [ [ a b ] _ ] [ b ( + a b ) ] ) ] ( f i r s t ( r e d u c e f i b [ 0 N 1 N ] ( r a n g e 0 i ) ) ) ) )
eager evaluation - - H a s k e l l f i b o n a c c i 4 : : I n t - > I n t e g e r f i b o n a c c i 4 i = f i b s ! ! i w h e r e f i b s = m a p f s t $ i t e r a t e ( \ ( a , b ) - > ( b , a + b ) ) ( 0 , 1 ) ; ; C l o j u r e ( d e f n f i b o n a c c i 4 [ i ] ( l e t [ f i b s ( m a p f i r s t ( i t e r a t e ( f n [ [ a b ] ] [ b ( + a b ) ] ) [ 0 N 1 N ] ) ) ] ( n t h f i b s i ) ) )
i b o n a c c i 5 : : I n t - > I n t e g e r f i b o n a c c i 5 i = f i b s ! ! i w h e r e f i b s = 0 : 1 : z i p W i t h ( + ) f i b s ( t a i l f i b s ) ; ; C l o j u r e ( d e f n f i b o n a c c i 5 [ i ] ( l e t f n [ ( f i b s [ a b ] ( c o n s a ( l a z y - s e q ( f i b s b ( + a b ) ) ) ) ) ] ( n t h ( f i b s 0 N 1 N ) i ) ) )