在Haskell中,有两种为类型提供别名的方法:type和newtype。 type提供类型同义词,这意味着同义词由类型检查器视为完全相同的原始类型: type UserId = Int
hasAccess :: UserId -> Bool
hasAccess id = {-- stuff --}
-- Elsewhere in the program
login :: Int ->
我想了解Monads made difficult的交代,我有一个很难搞清楚以下NEWTYPE定义: newtype (FComp g f) x = FComp { unCompose :: g (f x) }
instance (Functor b c f, Functor a b g) => Functor a c (FComp g f) where
fmap f (FComp
的派生实例,我使用ghci,该代码段 newtype Gold = Gold Int
deriving (Eq, Ord, Show, Num)
显示错误的 Can't make a derived instance of 'Num Gold':
'Num' is not a derivable class
Try GeneralizedNewTypeDerivi