Big expression in first argument - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Pedro Minicz

What do you guys do when you have to pass a big expression to the first argument of a two argument function?

parse :: String -> Maybe Expr
parse str = (`runReaderT` []) $ do
  tokens <- lift $ tokenize str
  parseExpr tokens

The above is the "best" solution I have right now.

Torsten Schmits

I usually use flip runReaderT [] do (with BlockArguments)

James Sully

so you could probably get away with defining it yourself if you're going to use it often

Georgi Lyubenov // googleson78

if the second argument is very small especially, I prefer the flip option also (because it avoids parens)
I've also seen

runReaderT act []
  act = ...
Georgi Lyubenov // googleson78

if both arguments are not small I would probably bite the bullet and split on multiple lines (with some do abuse to avoid parens :sweat_smile: )

  do 3 + 5
  do 4 + 6