Is it possible to define a commit declaration in a REPL?

I like to play REPL, as it is a very quick and easy way to try out new things. Some aspects of the language, as you know, are executed differently in REPL, and not in modules, as one of them multiline definitions are used.

Now, interestingly, in which case I can declare a statement commit in the REPL. A naive attempt ... surprise ... does not work.

Prelude> let (f ยท g) x = f(g(x)) Prelude> infixl 7 ยท 
+6
source share
1 answer

You can declare a commit using multi-line definitions such as

 >>> :{ >>> let infixl 7 *** >>> (f *** g) (a,b) = (fa, gb) >>> :} >>> (negate *** show) (1,2) (-1,"2") 

Edit: Although, interestingly, the fix does not appear when you ask GHCI about a function

 >>> :i *** (***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') -- Defined at <interactive>:10:8 

compared with

 >>> :i && (&&) :: Bool -> Bool -> Bool -- Defined in `GHC.Classes' infixr 3 && 
+9
source

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


All Articles