I love to play around in the REPL as it is a really fast and simple way of trying out new things. Certain aspects of the language is, as you know, done differently in the REPL as opposed to within modules, multi-line definitions being one of them.
Now, I wonder if, and in that case how, I can declare operator fixity in the REPL. The naive attempt...surprise...does not work.
Prelude> let (f · g) x = f(g(x))
Prelude> infixl 7 ·
You can declare fixity using multi-line definitions like this
>>> :{
>>> let infixl 7 ***
>>> (f *** g) (a,b) = (f a, g b)
>>> :}
>>> (negate *** show) (1,2)
(-1,"2")
Edit: Although, interestingly, the fixity isn't displayed when you ask GHCI about the function
>>> :i ***
(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
-- Defined at <interactive>:10:8
compared to
>>> :i &&
(&&) :: Bool -> Bool -> Bool -- Defined in `GHC.Classes'
infixr 3 &&
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With