简体   繁体   中英

How to implement this functionality in Haskell?

I have defined a data type as follows in Haskell,

data Numbers = "1" | "2" | "3" | "4" | "5"

I want to write a function which will give me the next number if given a number, except if I give it 4(I do not want it to give me 5 then).

next :: Numbers -> Numbers
next number = .....

I am a bit lost on how I can do this. Any suggestions?

You're probably looking for pattern matching syntax .

If you want to go for a more advanced solution, look into deriving Enum and the succ method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM