mxgr
1
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
jaror
2
I don’t think this is possible.
aidylns
3
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)
Leary
5
There’s an old trick to use an expression “infix”: enclose it in & and $.
throw DivideByZero &catch @ArithException$ \e ->
print ("lol: " <> show e)
jaror
6
For this particular example, I’d suggest rewriting it like this:
throw DivideByZero `catch` \(e :: ArithException) -> print $ "lol: " <> show e
mxgr
7
fast and simple enough, thanks all for suggestions
mxgr
8
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
(◂) = (&)
(▸) = ($)