Reputation: 12316
i have this data type in haskell
type Coordinate = (Int,Int)
type Skyline = [Coordinate]
And im trying to do:
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)
So, im trying to call to subcombina with
(((leftElementOfFirstLeftListTuple,rigthElementOfFirstLeftListTuple):restOfList,anyInteger),((leftElementOfFirstRigthListTuple,rigthElementOfFirsttRigthLListTuple):restOfList,anyInteger),
anyInteger)
And im getting this errors:
: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.
I think i'm mixing types but i cannot found where.
Upvotes: 0
Views: 104
Reputation: 48601
You are attempting to call max
using (among other things)
max(ai uad)
This says "Apply the function ai
to the value uad
and apply max
to the result." You probably meant to use
max ai uad
Upvotes: 4
Reputation: 36339
You have something like
max (ai uad)
in your code. This applies ai
to uad
But I guess what you wanted was simply:
max ai uad
Upvotes: 2