-1

I want to create a function for a calender programm, that does the following:

proceed :: Day -> Int -> Day
> proceed Mon 9
Wed

The function proceed should tell me, what weekday it is in 9 days, if today is Monday.

Now I try this:

data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun deriving Show

next :: Day -> Day
next Mon = Tue
next Tue = Wed
next Wed = Thu
next Thu = Fri
next Fri = Sat
next Sat = Sun
next Sun = Mon

proceed :: Day -> Int -> Day
proceed d a = if a==0 then next d
              else proceed (next d) (a-1) 

I try :

proceed Mon 9
Thu

But that's wrong, the right answear is Wed!!!!!!! I don't know where I've made the mistake.

basti12354
  • 2,490
  • 4
  • 24
  • 43
  • 1
    Did you mean `if a == 0 then d else proceed (next d) (a-1)`? It looks like you just have an off by one error. – bheklilr May 05 '14 at 21:41
  • Also, it's really helpful to actually state what your problem is. This post doesn't have a question in it, I would suggest editing it with more information about what isn't correct about your code. – bheklilr May 05 '14 at 21:42
  • I add some more information! – basti12354 May 05 '14 at 21:45
  • Is this a different question from this one? http://stackoverflow.com/questions/23481043/how-to-write-a-which-day-is-it-after-x-days-recursion-in-haskell – Rein Henrichs May 05 '14 at 21:49
  • yeah it is another question! I've only made a off by one error. – basti12354 May 05 '14 at 21:54

1 Answers1

1

Thanks to bheklilr

if a == 0 then d else proceed (next d) (a-1)

It was only an off by one error!

basti12354
  • 2,490
  • 4
  • 24
  • 43