The other day I found this blog post on using GADTs to write more usable C style Haskell with effects, references and loops. I couldn't get the example to typecheck without unsafe code, so I decided to write my own version. I wanted the behavior of expressions and operators to be similar to that of C. This is what I came up with: swap(r1, r2) = function $ do { z <- auto undefined; z =: r1; r1 =