首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >duple类型错误的Haskell元组

duple类型错误的Haskell元组
EN

Stack Overflow用户
提问于 2016-03-28 04:41:25
回答 2查看 95关注 0票数 0

我在haskell中有这样的数据类型

代码语言:javascript
复制
type Coordinate = (Int,Int)
type Skyline = [Coordinate]

我试着这样做:

代码语言:javascript
复制
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

代码语言:javascript
复制
(((leftElementOfFirstLeftListTuple,rigthElementOfFirstLeftListTuple):restOfList,anyInteger),((leftElementOfFirstRigthListTuple,rigthElementOfFirsttRigthLListTuple):restOfList,anyInteger),
anyInteger)

我得到了这个错误:

代码语言:javascript
复制
: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.

我想我在混合类型,但我找不到在哪里。

EN

回答 2

Stack Overflow用户

发布于 2016-03-28 04:48:01

您正在尝试使用(除其他外)调用max

代码语言:javascript
复制
max(ai uad)

这说明“将函数ai应用于值uad,并将max应用于结果。”你可能是想用

代码语言:javascript
复制
max ai uad
票数 4
EN

Stack Overflow用户

发布于 2016-03-28 04:45:03

你有类似这样的东西

代码语言:javascript
复制
max (ai uad) 

在你的代码中。这适用于uadai,但我猜您想要的很简单:

代码语言:javascript
复制
max ai uad
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36252413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档