创建一个`newtype也许a`

时间:2014-07-30 03:21:12

标签: haskell newtype

我为newtype创建了Maybe Int

Prelude> newtype MaybeTuple = MaybeTuple { getMaybe :: Maybe Int}
Prelude> let m = MaybeTuple (Just 5)
Prelude> getMaybe m
Just 5

但是如何创建newtype的通用Maybe a

1 个答案:

答案 0 :(得分:18)

a添加为类型参数:

newtype MaybeTuple a = MaybeTuple { getMaybe :: Maybe a }