SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
28.
カリー化
ある関数の引き数の一部に値を適用させた関数を
返すようにすること
(+) :: Num (a) => a -> a -> a
inc :: Num (a) => a -> a
inc a = 1 + a
=> inc = (+) 1
(*) :: Num (a) => a-> a -> a
twice :: Num (a) => a -> a
twice a = 2 * a
=> twice = (*) 2
29.
Haskell の引数を2つ以上とる関数
実は、引数を2つ以上とる関数は高階関数
Prelude> :t (+)
(+) :: (Num a) => a -> a -> a
Prelude> :t (+) 1
(+) 1 :: (Num t) => t -> t
(+) は
a と a を受け取って a を返す関数( (a -> a) -> a ) ではなく
a を受け取って、a を受け取って a を返す関数を返す関数
(a -> ( a -> a)) である