如果我有错误数据类型:
data Error a = Fail|Ok a
deriving (Eq, Ord, Show)
如果某些内容返回Error a
,我怎么才能自己获取a,以便我可以使用它?
答案 0 :(得分:4)
您需要使用pattern matching。例如:
case errorValue of
Fail -> ... -- Do something if it was a fail
Ok a -> ... -- Do something involving a if it was OK