2016-06-20 13 views
1
data A = B | C Int 

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

私イドリス0.11.2で奇妙な構文エラーが

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

の構文エラーを示します。 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 

エラーメッセージが表示されるはずですか?私は構文に何か間違って見ることはできません。

ありがとうございました。

答えて

2

実装では埋め込み演算子を使用できません(今のところはそうです)。代わりに接頭辞にラップしてください:

data A = B | C Int 

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

ブリリアント!ありがとう。 – RhubarbAndC