Haskell : multiple declarations of “” …?

前端 未结 3 1773
慢半拍i
慢半拍i 2021-01-22 07:49

Hey guys so here is my code on which I get the weird error of \"Multiple Declarations of mirror\". I have other functions before that but none of them are named mirror... Any id

相关标签:
3条回答
  • 2021-01-22 08:15

    Line 2 and line 3 have conflicting types: you've defined mirror to be the constant undefined, and then attempt to define it as a one-argument function. Removing line 2 should fix the problem; it's not clear why you wrote it in the first place.

    0 讨论(0)
  • 2021-01-22 08:35

    Multiple definitions of a function must have the same number of arguments left of the equals sign. This is not required from a theory standpoint (note: one of the definitons could certainly be a lambda or return another function) but people seem to like it as such definitions typically indicate a bug.

    Specifically, you have one definition with zero arguments:

    mirror = undefined
    

    And one definition with one argument:

    mirror (Node tL x tR) = Node x mirror tR mirror tL
    

    you probably want:

    mirror _              = undefined
    mirror (Node tL x tR) = Node x mirror tR mirror tL
    
    0 讨论(0)
  • 2021-01-22 08:35

    You have conflicting definitions for mirror. The first clause,

    mirror = undefined
    

    is a catch-all, so the definition is considered finished by the compiler. The next clause is then considered to start a new definition. You should remove the undefined line.

    0 讨论(0)
提交回复
热议问题