Created
March 4, 2015 11:55
-
-
Save shigemk2/d7f628a32dd858b35481 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 | |
deriving Show -- ココ | |
-- 分解しながら代入する | |
-- パターンマッチで分解 | |
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 -- 部分適用 | |
print $ Circle 10 20 30 | |
print $ map (Circle 10 20) [4,5,6,6] | |
where | |
c = Circle 1 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment