Why (!!) and (.) Have priority 9?

New to Haskell, and I missed a simple error in this snippet of expression

matches !! length . count

can't mix '!!' [infixl 9] and '.' [infixr 9] in the same infix expression

This surprised me - why do these operators share the assumption? What prevented Haskell designers from installing (.)with higher accuracy than (!!)?

I cannot imagine that this was simply missed, so I assume that there is a rationale that I am missing.

Note I understand that applying (!!)to a function consisting of (.)will still result in an error at compile time. I am wondering why Haskell was designed so that this is an unexpected error message.

+4
source share
2 answers

I rummaged. There is probably no rhyme or reason for two infix operators that have the same priority. In a Haskell 1.0 report released in 1990, the statement (!!)was found in the PreludeList.hs file, and the statement (.)was in the Prelude.hs file. Since they deal with completely different things (composition of functions and indexing of the list), and they were in completely different files, it is very likely that they were not cross-coordinated.

In addition, the report hardly mentioned these features in the prelude. (.)mentioned in only one liner, since the compositional function was (!!)not mentioned at all outside the actual source file.

. , , Haskell, , . Haskell - , . , (, , !) , .

+11

Haskell .

grep -hor '^infix[lr]\{0,1\} .*$' ghc/libraries/ | sort -u

GHC 137 . , : 0 9 , .

  • $ , (fixity 0)
  • >>= $ (fixity 1)
  • || >>= (fixity 2)
  • && || (fixity 3)
  • == && (fixity 4)
  • ++ == ( 5)
  • + ++ (fixity 6)
  • * + (fixity 7)
  • ^ * (fixity 8)
  • !! ^ (fixity 9)
  • . , (fixity 9)

, !! .. , , , , . !! .

+8

Source: https://habr.com/ru/post/1662787/


All Articles