How can I determine if one Enum value is the successor of another?
问题 I'm trying to write a function that tells me whether one Enum is the successor of another. Here was my first attempt: isSuccessorOf x y = x == succ y Looks reasonable. Let's try it: λ> isSuccessorOf 3 2 True λ> isSuccessorOf 1 5 False λ> isSuccessorOf 3 (maxBound :: Int) *** Exception: Prelude.Enum.succ{Int}: tried to take `succ' of maxBound Whoops. That should have been False . Let's make sure we don't try to do succ maxBound : isSuccessorOf x y = y /= maxBound && x == succ y Let's try it