双重类型错误的Haskell元组
我在haskell中有这种数据类型双重类型错误的Haskell元组,haskell,Haskell,我在haskell中有这种数据类型 type Coordinate = (Int,Int) type Skyline = [Coordinate] 我正在努力做到: combina :: (Skyline, Skyline) -> Skyline combina ([], x) = x combina (x, []) = x combina ((ii, ia):ri, (di, da):rd) = subcombina(((ii, ia):ri,0), (((di, da):rd),0)
type Coordinate = (Int,Int)
type Skyline = [Coordinate]
我正在努力做到:
combina :: (Skyline, Skyline) -> Skyline
combina ([], x) = x
combina (x, []) = x
combina ((ii, ia):ri, (di, da):rd) = subcombina(((ii, ia):ri,0), (((di, da):rd),0), 0)
where subcombina(((ii, ai):ri,uai), (((id, ad):rd),uad), uaa)
| ai < ad && max(uai uad) /= uaa = (ii, max ai uad) : subcombina((ri,ai), ((id, ad):rd, uad), max(ai uad))
| ai < ad && max(uai uad) == uaa = subcombina((ri,ai), ((id, ad):rd, uad), uaa)
| ((ai > ad) || (ai == ad)) && max(uai uad) /= uaa = (id, max uai ad) : subcombina(((ii, ai):ri,uai),(rd, ad), max (uai ad))
| ((ai > ad) || (ai == ad)) && max (uai uad) /= uaa = subcombina(((ii, ai):ri,uai),(rd, ad), uaa)
我得到了这个错误:
:l Skyline
[1 of 1] Compiling Skyline ( Skyline.hs, interpreted )
Skyline.hs:26:38:
Couldn't match type ‘t0 -> a0’ with ‘Int’
Expected type: Skyline
Actual type: [(Int, t0 -> a0)]
In the expression:
subcombina (((ii, ia) : ri, 0), (((di, da) : rd), 0), 0)
In an equation for ‘combina’:
combina ((ii, ia) : ri, (di, da) : rd)
= subcombina (((ii, ia) : ri, 0), (((di, da) : rd), 0), 0)
where
subcombina (((ii, ai) : ri, uai), (((id, ad) : rd), uad), uaa)
| ai < ad && max (uai uad) /= uaa
= (ii, max ai uad)
: subcombina ((ri, ai), ((id, ad) : rd, uad), max (ai uad))
| ai < ad && max (uai uad) == uaa
= subcombina ((ri, ai), ((id, ad) : rd, uad), uaa)
| ((ai > ad) || (ai == ad)) && max (uai uad) /= uaa
= (id, max uai ad)
: subcombina (((ii, ai) : ri, uai), (rd, ad), max (uai ad))
| ((ai > ad) || (ai == ad)) && max (uai uad) /= uaa
= subcombina (((ii, ai) : ri, uai), (rd, ad), uaa)
Skyline.hs:26:55:
Couldn't match expected type ‘t0 -> a0’ with actual type ‘Int’
In the expression: ia
In the first argument of ‘(:)’, namely ‘(ii, ia)’
Skyline.hs:26:59:
Couldn't match type ‘Int’ with ‘t0 -> a0’
Expected type: [(Int, t0 -> a0)]
Actual type: [Coordinate]
In the second argument of ‘(:)’, namely ‘ri’
In the expression: (ii, ia) : ri
Skyline.hs:26:73:
Couldn't match expected type ‘t0 -> a0’ with actual type ‘Int’
In the expression: da
In the first argument of ‘(:)’, namely ‘(di, da)’
Skyline.hs:26:77:
Couldn't match type ‘Int’ with ‘t0 -> a0’
Expected type: [(Int, t0 -> a0)]
Actual type: [Coordinate]
In the second argument of ‘(:)’, namely ‘rd’
In the expression: ((di, da) : rd)
Skyline.hs:28:103:
Occurs check: cannot construct the infinite type: t1 ~ t1 -> a
Expected type: (t1 -> a) -> a
Actual type: t1 -> a
Relevant bindings include
uaa :: a -> a (bound at Skyline.hs:27:62)
uad :: t1 -> a (bound at Skyline.hs:27:56)
rd :: [(t, t1 -> a)] (bound at Skyline.hs:27:52)
ad :: t1 -> a (bound at Skyline.hs:27:48)
uai :: (t1 -> a) -> a (bound at Skyline.hs:27:35)
ri :: [(t, t1 -> a)] (bound at Skyline.hs:27:32)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
In the expression: ai
In the expression: (ri, ai)
Failed, modules loaded: none.
:l天际线
[1/1]编译Skyline(Skyline.hs,已解释)
天际线。hs:26:38:
无法将类型“t0->a0”与“Int”匹配
预期类型:Skyline
实际类型:[(Int,t0->a0)]
在表达式中:
亚ombina((ii,ia):ri,0),((di,da):rd,0),0)
在“combina”的方程式中:
组合((ii,ia):ri,(di,da):rd)
=子组合((ii,ia):ri,0),((di,da):rd),0),0)
哪里
亚ombina((ii,ai):ri,uai),((id,ad):rd,uad),uaa)
|aiad)| |(ai==ad))&&max(uai uad)/=uaa
=(id,最大uai ad)
:次组合((ii,ai):ri,uai,(rd,ad),最大值(uai-ad))
|((ai>ad)| |(ai==ad))&&max(uai uad)/=uaa
=子组合((ii,ai):ri,uai,(rd,ad),uaa)
天际线。hs:26:55:
无法将预期类型“t0->a0”与实际类型“Int”匹配
在表达式中:ia
在“(:)”的第一个参数中,即“(ii,ia)”中
天际线。hs:26:59:
无法将类型“Int”与“t0->a0”匹配
预期类型:[(Int,t0->a0)]
实际类型:[坐标]
在“(:)”的第二个参数中,即“ri”
在表达式中:(ii,ia):ri
天际线。hs:26:73:
无法将预期类型“t0->a0”与实际类型“Int”匹配
在表达式中:da
在“(:)”的第一个参数中,即“(di,da)”
天际线。hs:26:77:
无法将类型“Int”与“t0->a0”匹配
预期类型:[(Int,t0->a0)]
实际类型:[坐标]
在“(:)”的第二个参数中,即“rd”
在表达式中:((di,da):rd)
天际线。hs:28:103:
发生检查:无法构造无限类型:t1~t1->a
预期类型:(t1->a)->a
实际类型:t1->a
相关绑定包括
uaa::a->a(在天际线处绑定。hs:27:62)
uad::t1->a(在天际线处绑定。hs:27:56)
rd::[(t,t1->a)](在天际线处绑定。hs:27:52)
广告:t1->a(在天际线绑定。hs:27:48)
uai::(t1->a)->a(在天际线处绑定。hs:27:35)
ri::[(t,t1->a)](在天际线处绑定。hs:27:32)
(某些绑定被抑制;使用-fmax-related-binds=N或-fno-max-related-binds)
在表达式中:ai
在表达式中:(ri,ai)
失败,已加载模块:无。
我想我是在混合类型,但我找不到在哪里。你有类似的
max (ai uad)
在你的代码中。这适用于ai
到uad
但我想你想要的只是:
max ai uad
你有点像
max (ai uad)
在你的代码中。这适用于ai
到uad
但我想你想要的只是:
max ai uad
您正在尝试使用(除其他外)调用
max
这表示“将函数ai
应用于值uad
,并将max
应用于结果。”您可能打算使用
max ai uad
您正在尝试使用(除其他外)调用
max
这表示“将函数ai
应用于值uad
,并将max
应用于结果。”您可能打算使用
max ai uad
除了类型错误之外,我认为这个函数太大太神秘了。你能把它分成更小的、独立的部分吗?你能用简单的语言在代码中写下注释来解释每一个片段的用途吗?除了类型错误,我认为这个函数太大太神秘了。你能把它分成更小的、独立的部分吗?你能用简单的语言在代码中写下注释来解释每件作品的用途吗?