Couldn't match expected type ‘Int -> [Char]’ with actual type ‘Int’ Possible cause: ‘mod’ is applied to too many arguments

Viewed 103

my code:

weekDay :: Int -> Int -> Int -> Int -> [Char]
weekDay day month year = mod (day + x + (31 * m0) `div` 12) 7
          where y0 = year - ((14 - month) `div` 12)
                 x = y0 + y0 `div` 4 - y0 `div `100 + y0 `div` 400
                 m0 = month + 12 * ((14 - month) `div` 12) - 2
                 day month year = case day month year of
                           0 -> Sonntag
                           1 -> Montag
                           2 -> Dienstag
                           3 -> Mittwoch
                           4 -> Donnerstag
                           5 -> Freitag
                           6 -> Samstag
                           otherwise -> error

Errors:

 error:
    • Couldn't match expected type ‘Int -> [Char]’
                  with actual type ‘Int’
    • Possible cause: ‘mod’ is applied to too many arguments
      In the expression: mod (day + x + (31 * m0) `div` 12) 7
error:
 • Non type-variable argument in the constraint: Eq ([Char] -> a)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        day :: forall a t1 t2.
               (Eq ([Char] -> a), Num ([Char] -> a)) =>
               t1 -> t2 -> [Char] -> a
1 Answers

You can simplify your code to determine the cause of the error. For example

weekDay :: Int -> Int -> Int -> Int -> [Char]
weekDay day month year = mod 4 7

would result in the same problem as would

weekDay :: Int -> Int -> Int -> Int -> [Char]
weekDay day month year = 10

and

weekDay :: Int -> [Char]
weekDay = 10

I found this technique extremely versatile and useful to solve all sorts of nasty problems.

Related