i want to do something like:
succ' :: (Bounded a, Eq a, Enum a) => a -> a
succ' n
| n == (maxBound :: a) = minBound :: a
| otherwise = succ n
but this does not work. how to solve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need the type annotations, and they’re the source of the errors you’re getting:
(This works in Haskell 98 and Haskell 2010, so pretty much any compiler you’ve got lying around .)
Also, I indented the
|a little, because they can’t line up with the start of the function; they’re part of the definition ofsucc', not standalone code.Here’s some test data:
I got
[B,C,A].