我正在尝试编写一个函数,它将三个列表作为参数,并连续创建一个列表,每个列表都有一个三元组.
我给出的例子就是:zip3Lists [1, 2, 3] [4, 5, 6] ['a', 'b', 'c']
会产生[(1, 4, 'a'), (2, 5, 'b'), (3, 6, 'c')]
.
到目前为止我所拥有的是:
zipThree [] [] [] = []
zipThree [] [] [x] = [x]
zipThree [] [x] [] = [x]
zipThree [x] [] [] = [x]
zipThree (x:xs) (y:ys) (z:zs) = (x, y, z) : zipThree xs ys zs
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误:
haskell1.hs:32:33: error:
• Occurs check: cannot construct the infinite type: c ~ (c, c, c)
Expected type: [c] …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数,它接受一个日期列表(当前处于表单(年,月,日),其中每个是Int:(Int,Int,Int))和一个月(作为Int)并返回次数该月出现在日期列表中.
我收到一个错误:"在输入上解析错误 - >"关于我在函数签名中的第一个' - >':
numberInMonth [(Int, Int, Int)] -> Int -> Int
numberInMonth ((y,m,d) : rst) month =
if y == month then 1 +(numberInMonth rst)
else numberInMonth rst
Run Code Online (Sandbox Code Playgroud)
有关为什么不解析的任何想法?
我正在编写一个函数,它接受日期列表并计算(Int,Int,Int).如果列表为空,则计算结果为Nothing,并计算为Just d,其中d是列表中最早的Date.我的日期数据结构如下:
data Date = Date Int Int Int
deriving (Show)
Run Code Online (Sandbox Code Playgroud)
这是一个帮助函数,我用它来确定Date是否更旧:
isOlder2 :: Date -> Maybe Date -> Bool
isOlder2 (Date x y z) (Just (Date a b c))
| x < a = True
| x > a = False
| (x == a)&&(y < b) = True
| (x == a)&&(y > b) = False
| (x == a) && (y ==b) &&(z < c) =True
| (x == a) && (y ==b) &&(z > c) = …
Run Code Online (Sandbox Code Playgroud)