奇怪的语法错误

时间:2016-06-20 17:59:23

标签: idris

data A = B | C Int

implementation Semigroup A where
  B <+> x = x
  x <+> B = x
  C m <+> C n = C (m + n)

给我一​​个语法错误

./Nodes/Test.idr:3:1: error: expected: ";",
    "|", declaration, end of input
implementation Semigroup A where 
^                                
Type checking ./Nodes/Test.idr

在Idris 0.11.2中。删除implementation会改为显示以下消息:

./Nodes/Test.idr:3:13: error: expected: "@",
    "with", argument expression,
    constraint argument,
    function right hand side,
    implicit function argument,
    with pattern
Semigroup A where 
            ^     
Type checking ./Nodes/Test.idr

我应该收到错误消息吗?我看不出语法有什么问题。

感谢。

1 个答案:

答案 0 :(得分:2)

你不能在实现中使用中缀运算符(现在,我猜)。相反,将它们包装为前缀:

data A = B | C Int

implementation Semigroup A where
  (<+>) B x = x
  (<+>) x B = x
  (<+>) (C m) (C n) = C (m + n)