data Int = -2147483648 | -2147483647 | ... | -1 | 0 | 1 | ... | 2147483647 | 2147483648
data Shape = Circle Float Float Float | Rectangle Float Float Float Float
ghc> :t Circle
Circle :: Float -> Float -> Float -> Shape
ghc> :t Rectangle
Rectangle :: Float -> Float -> Float -> Float -> Shape
# area.hs
area :: Shape -> Float
area (Circle _ _ r) = pi * r ^ 2
area (Rectangle x1 y1 x2 y2) = (abs $ x2 - x1) * (abs $ y2 - y1)
ghc> area $ Circle 1 2 3
28.274334
ghc> area $ Rectangle 0 0 10 100
1000.0
data Shape = Circle Float Float Float | Rectangle Float Float Float Float deriving (Show)
ghc> Circle 10 20 5
Circle 10.0 20.0 5.0
module Shapes
( Point(..)
, Shape(..)
, area
, nudge
, baseCircle
) where
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
, height :: Float
} deriving (Show)
ghc> :t firstName
firstName :: Person -> String
ghc> :t age
age :: Person -> Int
ghc> Person {firstName="PigBrain", lastName="Lee", age=1, height=10.0}
Person {firstName = "PigBrain", lastName = "Lee", age = 1, height = 10.0}
data Maybe a = Nothing | Just a
ghc> data Maybe a = Nothing | Just a deriving (Show)
ghc> Just 3 :: Maybe Int
Just 3
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
, height :: Float
} deriving (Eq)
ghci> mikeD = Person {firstName = "Michael", lastName="Diamond", age = 43}
ghci> adRock = Person {firstName = "Adam", lastName="Horovitz", age = 41}
ghci> mikeD == adRock
False
ghci> mikeD == mikeD
True