开发者

Deriving a type and its dependencies

开发者 https://www.devze.com 2022-12-17 05:56 出处:网络
I\'ve been playing with newtype wrappers for my indexes to avoid 开发者_JAVA技巧bugs, and I have some code like this:

I've been playing with newtype wrappers for my indexes to avoid 开发者_JAVA技巧bugs, and I have some code like this:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

newtype PersonIdx = PersonIdx Int
  deriving (Enum, Eq, Integral, Num, Ord, Real, Show)

To derive Integral, one must derive all its dependencies as well (hence the above list of type-classes).

Is there a way to make it derive all the dependencies of Integral along with it? I would imagine something like:

newtype PersonIdx = PersonIdx Int
  deriving (Integral(..))


No, there is no shortcut. You'll have to derive from all dependent typeclasses explicitly, but can easily find these by typing :i Integral in ghci.

0

精彩评论

暂无评论...
验证码 换一张
取 消