Is there a handy list of operators and their precedence somewhere? Michael
Take a look to the Haskell Report: http://www.haskell.org/onlinereport/haskell2010/haskellch9.html#x16-1710009 -- Daniel Díaz
Thanks, Daniel. This be all of them? Michael infixr 9 . infixr 8 ^, ^^, ⋆⋆ infixl 7 ⋆, /, ‘quot‘, ‘rem‘, ‘div‘, ‘mod‘ infixl 6 +, - -- The (:) operator is built-in syntax, and cannot legally be given -- a fixity declaration; but its fixity is given by: -- infixr 5 : infix 4 ==, /=, <, <=, >=, > infixr 3 && infixr 2 || infixl 1 >>, >>= infixr 1 =<< infixr 0 $, $!, ‘seq‘ --- On Mon, 9/6/10, Daniel Díaz <lazy.ddiaz@gmail.com> wrote: From: Daniel Díaz <lazy.ddiaz@gmail.com> Subject: Re: [Haskell-cafe] Operator precedence To: "michael rice" <nowgate@yahoo.com>, haskell-cafe@haskell.org Date: Monday, September 6, 2010, 1:06 PM Take a look to the Haskell Report: http://www.haskell.org/onlinereport/haskell2010/haskellch9.html#x16-1710009 -- Daniel Díaz
Those are all operators in Prelude. See a concrete library for their operator precedences. -- Daniel Díaz
A "concrete" library? I'm playing around with Data.Bits. It has .&. and .|. which I assume are functions (rather than operators) because I don't see and infix statement for them. Correct? Michael --- On Mon, 9/6/10, Daniel Díaz <lazy.ddiaz@gmail.com> wrote: From: Daniel Díaz <lazy.ddiaz@gmail.com> Subject: Re: [Haskell-cafe] Operator precedence To: "michael rice" <nowgate@yahoo.com>, haskell-cafe@haskell.org Date: Monday, September 6, 2010, 1:17 PM Those are all operators in Prelude. See a concrete library for their operator precedences. -- Daniel Díaz
On Mon, Sep 6, 2010 at 1:37 PM, michael rice <nowgate@yahoo.com> wrote:
A "concrete" library?
I'm playing around with Data.Bits. It has .&. and .|. which I assume are functions (rather than operators) because I don't see and infix statement for them. Correct?
.|. and .&. are operators because they are made from symbol characters. Operators default to infixl 9 unless specified otherwise, so no infix declaration is needed. However, Data.Bits does have infix declarations for .&. and .|. : infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR` infixl 7 .&. infixl 6 `xor` infixl 5 .|. If you want to check the fixity of an operator, use :info in GHCi. Prelude Data.Bits> :i .|. class (Num a) => Bits a where ... (.|.) :: a -> a -> a ... -- Defined in Data.Bits infixl 5 .|. -- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/>
Hi David, You're right, I keep forgetting to look at the source code. And I wasn't aware of the info (:i) command. Should come in handy in the future. Michael --- On Mon, 9/6/10, David Menendez <dave@zednenem.com> wrote: From: David Menendez <dave@zednenem.com> Subject: Re: [Haskell-cafe] Operator precedence To: "michael rice" <nowgate@yahoo.com> Cc: haskell-cafe@haskell.org, "Daniel Díaz" <lazy.ddiaz@gmail.com> Date: Monday, September 6, 2010, 1:50 PM On Mon, Sep 6, 2010 at 1:37 PM, michael rice <nowgate@yahoo.com> wrote:
A "concrete" library?
I'm playing around with Data.Bits. It has .&. and .|. which I assume are functions (rather than operators) because I don't see and infix statement for them. Correct?
.|. and .&. are operators because they are made from symbol characters. Operators default to infixl 9 unless specified otherwise, so no infix declaration is needed. However, Data.Bits does have infix declarations for .&. and .|. : infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR` infixl 7 .&. infixl 6 `xor` infixl 5 .|. If you want to check the fixity of an operator, use :info in GHCi. Prelude Data.Bits> :i .|. class (Num a) => Bits a where ... (.|.) :: a -> a -> a ... -- Defined in Data.Bits infixl 5 .|. -- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/>
On Mon, Sep 6, 2010 at 2:21 PM, Daniel Díaz <danieldiaz@asofilak.es> wrote:
El Lun, 6 de Septiembre de 2010, 7:50 pm, David Menendez escribió:
Operators default to infixl 9 unless specified otherwise, so no infix declaration is needed.
Why there is a default infix? Why it is 9?
That's what the Haskell Report says: "Any operator lacking a fixity declaration is assumed to be infixl 9" (section 4.4.2). Any function with at least two arguments can be used as an operator, so there has to be a default. Presumably, infixl 9 was considered the least surprising. -- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/>
Hello michael, Monday, September 6, 2010, 9:00:32 PM, you wrote:
Is there a handy list of operators and their precedence somewhere?
unlike most languages, operators are user-definable in haskell. so there is no comprehensive list any function with two arguments van be used as operator: a `min` b any operator may be defined or used as a function: (&&) a b = ... main = print ((&&) True False) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (5)
-
Bulat Ziganshin -
Daniel Díaz -
Daniel Díaz -
David Menendez -
michael rice