Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 27, 2015 04:47
Show Gist options
  • Save motokiee/878e795891c7c15d31f1 to your computer and use it in GitHub Desktop.
Save motokiee/878e795891c7c15d31f1 to your computer and use it in GitHub Desktop.
自作データ型をはじめて作った #CodePiece
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment