시리즈: haskell
haskell
26 줄
· 업데이트 2026-02-03
shapeValidate.hs
haskell/shapeValidate.hs
module Shapes
( Shape(..)
, Validity(..)
, validShape
) where
-- Sum + product type
data Shape
= Circle Double -- radius
| Rectangle Double Double -- height, width
deriving (Show, Eq)
data Validity = Valid | Invalid
deriving (Show, Eq)
-- A circle is valid iff radius ≥ 0.
-- A rectangle is valid iff height ≥ 0 and width ≥ 0.
validShape :: Shape -> Validity
validShape shape =
case shape of
Circle r
| r < 0 -> Invalid
| otherwise -> Valid
Rectangle h w
| h < 0 || w < 0 -> Invalid
| otherwise -> Valid
관련 글
haskell
haskell
업데이트 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
글 읽기 →
haskell
haskell
업데이트 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
글 읽기 →
haskell
haskell
업데이트 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
글 읽기 →
haskell
haskell
업데이트 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
글 읽기 →
haskell
haskell
업데이트 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
글 읽기 →
haskell
haskell
업데이트 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
글 읽기 →