Skip to content

Instantly share code, notes, and snippets.

@zenloner
Created June 5, 2013 14:16
Show Gist options
  • Save zenloner/5714192 to your computer and use it in GitHub Desktop.
Save zenloner/5714192 to your computer and use it in GitHub Desktop.
data Point = Point Float Float deriving (Show)
data Shape = Circle Point Float | Rectangle Point Point deriving (Show)
area::Shape->Float
area (Circle _ r) = pi * r^2
area (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 -x1)*(abs $ y2-y1)
main = do
-- fun $ x... is the same as fun(x...)
print $ area $ Circle (Point 1 2) 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment