2009-06-06から1日間の記事一覧

http://ja.wikipedia.org/wiki/Haskell の逆ポーランド記法評価器

-- 逆ポーランド記法評価器 -- calc :: String -> [Float] calc = foldl f [] . words where f (x:y:zs) "+" = y+x:zs f (x:y:zs) "-" = y-x:zs f (x:y:zs) "*" = y*x:zs f (x:y:zs) "/" = y/x:zs f xs y = read y : xs 分かりやすく変数名を変えてみる。 ca…