I see two problems at least:<div><br></div><div>1) The type signatures (e.g. [colMeta] in the .urs file) haven't been updated to reflect the fact that the widget field will be a transaction.</div><div><br></div><div>2) The accumulating function passed to [foldR] doesn't treat its arguments like transactions. What you have now stitched together xml fragments, but we really want to string together transactions and stitch together the resulting xml. This will look something like this:</div><div><br></div><div>fn xTrans accTrans =></div><div> x <- xTrans;</div><div> acc <- accTrans;</div><div> return <xml>{x}{accTrans}</xml></div><div><br></div><div>The above code is a sketch. In particular, it doesn't deal with the possibly different types (e.g. you probably need a [useMore] somewhere).</div><div><br></div><div>A completely different approach might use something like Monad.exec or Monad.foldR. The latter may be a particularly good fit, but I haven't used it before. (You can find type signatures for these in lib/ur/monad.urs in the Ur/Web<span></span> directory).</div><div><br></div><div><br>On Monday, August 31, 2015, Stefan Scott <<a href="mailto:stefanscottalexx@gmail.com">stefanscottalexx@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>[Note: The following message can also be seen as a README on GitHub - with better formatting: <a href="https://github.com/StefanScott/UrWeb-Crud1-move-foldR" target="_blank">https://github.com/StefanScott/UrWeb-Crud1-move-foldR</a> ]</div><div><br></div><div>I am attempting make a minimal modification to the Crud1 demo, by moving the call to `@foldR` in `list()` to *before* the `return` statement. <br></div><div><br></div><div>The modified version now gives a kind unification error, apparently involving the 2nd argument to `@foldr` - `[ fn cols => xml form [] (map snd cols) ]`.</div><div><br></div><div>I am trying to figure out how such a minimal modification could result in a compile error.</div><div><br></div><div>The "diff" between the "before" and "after" can be seen at this link - also excerpted here below:</div><div><br></div><div><a href="https://github.com/StefanScott/UrWeb-Crud1-move-foldR/commit/04ca85962a5c95e8144c6e2a29df729d631b6187#diff-74e1ef1a69438025793099ad624ad8bcR63" target="_blank">https://github.com/StefanScott/UrWeb-Crud1-move-foldR/commit/04ca85962a5c95e8144c6e2a29df729d631b6187#diff-74e1ef1a69438025793099ad624ad8bcR63</a><br></div><div><br></div><div>BEFORE:</div><div><br></div><div> return <xml> (* <= the `return` *)</div><div> ...</div><div> {@foldR (* <= call to `@foldR`, will be moved *above* the `return` *)</div><div> [ colMeta ] </div><div> [ fn cols => xml form [] (map snd cols) ]</div><div> ( fn [nm :: Name] [t ::_] [rest ::_] [[nm] ~ rest] (col : colMeta t) acc => </div><div> <xml></div><div> <li> {cdata col.Nam}: {col.Widget [nm]}</li></div><div> {useMore acc}</div><div> </xml> )</div><div> <xml/></div><div> M.fl </div><div> M.cols} </div><div> ...</div><div> </xml></div><div><br></div><div>AFTER:</div><div><br></div><div>formFields <- @foldR (* <= call to `@foldR`, now moved *above* the `return` *)</div><div> [ colMeta ] </div><div> [ fn cols => xml form [] (map snd cols) ]</div><div> ( fn [nm :: Name] [t ::_] [rest ::_] [[nm] ~ rest] (col : colMeta t) acc => </div><div> <xml></div><div> <li> {cdata col.Nam}: {col.Widget [nm]}</li></div><div> {useMore acc}</div><div> </xml> )</div><div> <xml/></div><div> M.fl </div><div> M.cols;</div><div> return <xml> (* <= the `return` *)</div><div> ...</div><div> {formFields} (* <= call to `@foldR` was originally here *)</div><div> ...</div><div> </xml></div><div><br></div><div>I created a GitHub with just 2 commits, to illustrate the modification:</div><div><br></div><div> - commit 0: the original Crud1 (simplified to only do SELECT and INSERT); </div><div><br></div><div> - commit 1: the modified Crud1 - now, in function `list()`, the call to `@foldR` which computes the form fields has been moved to *before* the `return`. This gives following compile error:</div><div><br></div><div><a href="https://github.com/StefanScott/UrWeb-Crud1-move-foldR/blob/master/ERR.001.crudWidgetTxn1.ur" target="_blank">https://github.com/StefanScott/UrWeb-Crud1-move-foldR/blob/master/ERR.001.crudWidgetTxn1.ur</a><br></div><div><br></div><div>The modified version gives a kind unification failure:</div><div><br></div><div> Have con: </div><div><br></div><div> xml ([Dyn = (), Body = (), Form = ()]) ([])</div><div> (map (fn t :: (Type * Type) => t.2) M.cols)</div><div><br></div><div> Need con: </div><div><br></div><div> <UNIF:U408::Type -> Type> <UNIF:U409::Type></div><div><br></div><div> Kind unification failure</div><div><br></div><div> Have: {Type} -> Type</div><div> Need: Type -> Type</div><div><br></div><div>This appears to involve the second argument to `@foldR`, which is:</div><div><br></div><div> [ fn cols => xml form [] (map snd cols) ]</div><div><br></div><div>I thought that merely moving a chunk of code before a `return` statement like this wouldn't change much, so I don't understand what might be causing this kind unification failure in the modified version.</div><div><br></div><div>Thanks for any help!</div><div><br></div><div>###</div><div><br></div></div>
</blockquote></div>