Created
March 4, 2015 11:35
-
-
Save shigemk2/c65d29c1a0f5c1033c9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Shape = Circle Float Float Float | | |
Rectangle Float Float Float Float | |
-- 分解しながら代入する | |
-- パターンマッチで分解 | |
area :: Shape -> Float | |
area (Circle _ _ r) = pi * r ^ 2 | |
area (Rectangle x1 y1 x2 y2) = (abs $ x2 - x1) * (abs $ y2 - y1) | |
main = do | |
print $ area $ Circle 10 20 10 -- 314.15927 | |
print $ area $ Rectangle 0 0 100 100 -- 10000.0 | |
print $ area $ c 100 -- 部分適用 | |
where | |
c = Circle 1 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment