typeApplications in infix functions? [SOLVED]

Hi, I think it will be fast question/answer. Is there an opportunity to define typeApplications for infix functions?

I would like to move this

catch @ArithException (throw DivideByZero) (\ e -> print $ "lol: " <> show e)

to this, somehow

throw DivideByZero `catch` @ArithException (\ e -> print $ "lol: " <> show e)

is that possible? I read GHC guide, and didn’t find it
Also, I’ve tried different combinations for infix function but it didn’t work

as always, your answers will help me a lot

thanks

I don’t think this is possible.

This might be a good argument to allow more complex infix expressions? There are a few GHC issues about this I think.

There’s `already` enough “write-only” programming `languages - does` Haskell `really` have `to be ?another` one

Use an extra function:

valid m c h = c m h

valid (throw DivideByZero) (catch @ArithException) (\ e -> print $ "lol: " <> show e)
1 Like

There’s an old trick to use an expression “infix”: enclose it in & and $.

throw DivideByZero &catch @ArithException$ \e ->
  print ("lol: " <> show e)
4 Likes

For this particular example, I’d suggest rewriting it like this:

throw DivideByZero `catch` \(e :: ArithException) -> print $ "lol: " <> show e
1 Like

fast and simple enough, thanks all for suggestions

btw, beautiful usage of &

Ticket

You can simulate it with throw DivideByZero ◂catch @ArithException▸ (\ e -> print $ "lol: " <> show e)

infixl 3 ◂
infixl 3 ▸

(◂) :: a -> (a -> b) -> b
(▸) :: (a -> b) -> a -> b
(◂) = (&)
(▸) = ($)
2 Likes