我为newtype
创建了Maybe Int
:
Prelude> newtype MaybeTuple = MaybeTuple { getMaybe :: Maybe Int}
Prelude> let m = MaybeTuple (Just 5)
Prelude> getMaybe m
Just 5
但是如何创建newtype
的通用Maybe a
?
答案 0 :(得分:18)
将a
添加为类型参数:
newtype MaybeTuple a = MaybeTuple { getMaybe :: Maybe a }