gpt4 book ai didi

haskell - 无法将预期类型 ‘Int -> [Char]’ 与实际类型 ‘Int’ 匹配 可能的原因 : ‘mod’ is applied to too many arguments

转载 作者:行者123 更新时间:2023-12-02 14:46:54 25 4
gpt4 key购买 nike

我的代码:

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

错误:

 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

最佳答案

您可以简化代码以确定错误的原因。例如

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

会导致同样的问题

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

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

我发现这种技术非常通用,可用于解决各种棘手的问题。

关于haskell - 无法将预期类型 ‘Int -> [Char]’ 与实际类型 ‘Int’ 匹配 可能的原因 : ‘mod’ is applied to too many arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58604572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com