Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The fixity signature for ‘.++’ lacks an accompanying binding

Tags:

haskell

infixr 5 .++

I do this in ghci and it gives the error message.

<interactive>:26:10: error:
    The fixity signature for ‘.++’ lacks an accompanying binding

How can I fix it? Thank you!

like image 987
user8314628 Avatar asked Mar 05 '23 18:03

user8314628


1 Answers

Well like the error says, you indeed defined the fixity, but you still need to define a signature and implementation. Since otherwise, there is actually no operator (or at least we can not use such operator, which is usually why one declares such operator). Since Haskell can derive the signature itself, the signature is strictly speaking not necessary (although it is advisable to write one since it is probably a "top-level function").

For example:

infixr 5 .++
(.++) :: [a] -> [a] -> [a]
(.++) = (++)

Here the second line is the signature, and the third one the implementation. Of course you can pick another signature and implementation.

If you run this in an interpreter, you need to define these all in the same "statement". You can do so by grouping lines, for example with the :{ and :} commands:

Prelude> :{
Prelude| infixr 5 .++
Prelude| (.++) :: [a] -> [a] -> [a]
Prelude| (.++) = (++)
Prelude| :}
like image 166
Willem Van Onsem Avatar answered Mar 15 '23 15:03

Willem Van Onsem