我想知道我们是否能够控制数据类型并确定输入的数据是否存在于 Haskell 中?
例如:
data Ruler =Ruler Length Price deriving(Eq,Show)
data Wallet = Wallet Colour Ruler [Pencil] deriving(Eq,Show)
data Pencil =Pencil Penciltype Colour Price deriving(Eq,Show)
data Colour =Black | Blue | Green | Red deriving(Eq,Show)
data Penciltype =Leadpencil | Pen | Fountainpen | Feltpen deriving(Eq,Show)
type Price =Double
type Length =Int
那么有什么想法吗?
我想定义一个这样的函数:
isRulerAvailable :: Wallet-> Bool
if Ruler is Available in Wallet then True
else False