Bus errorとSegmentation faultに困ったら見るブログ

物理の研究者による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)

【Haskell】型宣言がまんどくさいとき、

(過去記事のコピペ 2013/07/14)

実はHaskellには型を推定してくれる機能があるのだ

hoge x = x * 2

とソースに書いておいて、

*Main> :t hoge
hoge :: Num a => a -> a
zipWith2 _ [] _ = []
zipWith2 _ _ [] = []
zipWith2 f (x:xs) (y:ys) = f x y : zipWith2 f xs ys

こんな関数でも?

*Main> :t zipWith2
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]

大丈夫です。