Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
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.
I usually use flip runReaderT [] do (with BlockArguments)
flip runReaderT [] do
BlockArguments
in the specific case there's this precedent in relude: https://hackage.haskell.org/package/relude-0.7.0.0/docs/Relude-Monad-Trans.html#v:usingReaderT
so you could probably get away with defining it yourself if you're going to use it often
if the second argument is very small especially, I prefer the flip option also (because it avoids parens) I've also seen
flip
runReaderT act [] where act = ...
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
f do 3 + 5 do 4 + 6
What do you guys do when you have to pass a big expression to the first argument of a two argument function?
The above is the "best" solution I have right now.
I usually use
flip runReaderT [] do
(withBlockArguments
)in the specific case there's this precedent in relude: https://hackage.haskell.org/package/relude-0.7.0.0/docs/Relude-Monad-Trans.html#v:usingReaderT
so you could probably get away with defining it yourself if you're going to use it often
if the second argument is very small especially, I prefer the
flip
option also (because it avoids parens)I've also seen
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: )