我是Haskell的新手.这是一些简单的代码:
module Src
( -- The 'Answer' type isn't exported
Shape(Circle), -- i.e 'Rectangle' data constructor isn't exported
Point(..),
area,
nudge
) where
data Answer = Yes | No deriving (Show)
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) …
Run Code Online (Sandbox Code Playgroud)