奇怪的语法错误
Weird syntax error
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
我应该收到一条错误消息吗?我看不出语法有什么问题。
谢谢。
您不能在实现中使用中缀运算符(我猜现在是这样)。相反,将它们包装到前缀:
data A = B | C Int
implementation Semigroup A where
(<+>) B x = x
(<+>) x B = x
(<+>) (C m) (C n) = C (m + n)
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
我应该收到一条错误消息吗?我看不出语法有什么问题。
谢谢。
您不能在实现中使用中缀运算符(我猜现在是这样)。相反,将它们包装到前缀:
data A = B | C Int
implementation Semigroup A where
(<+>) B x = x
(<+>) x B = x
(<+>) (C m) (C n) = C (m + n)