# Make it possible to evaluate monadic actions when assigning record fields

Neil Mitchell ndmitchell at gmail.com
Thu Jul 12 07:10:10 EDT 2007

```Hi

> Put differently, I don't see a compelling use-case for the proposed
> syntax extension. But I've seen many misused monads.

A compelling use-case:

Look at coreSimplifyExprUniqueExt

And from that file:

-- helpers, ' is yes, _ is no
coreCase__ x y = f \$ CoreCase x y ; coreCase_' x y = f .
CoreCase x =<< y
coreLet__  x y = f \$ CoreLet  x y ; coreLet_'  x y = f .
CoreLet  x =<< y
coreLam__  x y = f \$ CoreLam  x y ; coreLam_'  x y = f .
CoreLam  x =<< y
coreApp__  x y = f \$ CoreApp  x y ; coreApp'_  x y = f . flip
CoreApp y =<< x

i.e. i've manually defined ' and _ variants to thread monadic effects
through in quite horrible ways. The monad in question simply supplies
free variables, so could be applied in any order.

I think with this extension I can define:

coreCase x y = f \$ CoreCase x y
coreLet x y = f \$ CoreLet x y
...

And taking just one rule, before:

f (CoreApp (CoreLet bind xs) ys) = coreLet_' bind (coreApp__ xs ys)

After:

f (CoreApp (CoreLet bind xs) ys) = coreLet bind \$(coreApp xs ys)

Much nicer!

This extension seems like a great idea - my only concern would be
about the order of computations. Clearly left-to-right makes sense,
but this may break some natural intuition in Haskell:

flip f a b == f b a

flip f \$(a) \$(b) /= f \$(b) \$(a)

I don't think that is a show stopper though.

Thanks

Neil
```