我在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), 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)因此,我尝试使用以下命令调用subcombina
(((leftElementOfFirstLeftListTuple,rigthElementOfFirstLeftListTuple):restOfList,anyInteger),((leftElementOfFirstRigthListTuple,rigthElementOfFirsttRigthLListTuple):restOfList,anyInteger),
anyInteger)我得到了这个错误:
: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.我想我在混合类型,但我找不到在哪里。
发布于 2016-03-28 04:48:01
您正在尝试使用(除其他外)调用max
max(ai uad)这说明“将函数ai应用于值uad,并将max应用于结果。”你可能是想用
max ai uad发布于 2016-03-28 04:45:03
你有类似这样的东西
max (ai uad) 在你的代码中。这适用于uad的ai,但我猜您想要的很简单:
max ai uadhttps://stackoverflow.com/questions/36252413
复制相似问题