The placment of infix in chapter 4

The task is to rewrite the previous function but with an alias for filter.
My function looks like this

infix 4 filter as <$?>
keepNonNegativeRewrite :: Array Int -> Array Int
keepNonNegativeRewite arr = (\n -> n `mod` n >= 0) <$?> arr

but get this error output when run

$ spago test
Compiling Test.MySolutions
Error found:
in module Test.MySolutions
at test/MySolutions.purs:49:1 - 49:62 (line 49, column 1 - line 49, column 62)

  The type declaration for keepNonNegativeRewrite should be followed by its definition.


See https://github.com/purescript/documentation/blob/master/errors/OrphanTypeDeclaration.md for more information,
or to contribute content related to this error.


[error] Failed to build.

I looked at the source for <$> and it seems to use infixl at its definition, so I tried it as well and ran into same or similar error. I also tried placing the `<$?> somewhere else in the function, like how it’s shown in the book but with same error as well.

Also I’m not sure what the meaning of the number after infix means or if it has to be set to specific on.

Should the infix be declared in a different pattern or was the function wrong?

You’ve got a typo there :wink:

1 Like

This is definitely an error message that could be improved, especially if it appears to have been caused by a typo. Maybe we could include the name of the declaration that follows in the error message.

2 Likes