[Ur] 'Anonymous function remains' in state monad

Sergey Mironov grrwlf at gmail.com
Thu Aug 14 05:04:10 EDT 2014


Hi! I am trying to develop a method of writing more compact XML
generation code in UrWeb. My plan is to generate XML under the hood of
state monad and leave the "main function space" for wiring signals and
client-side logic (Haskell programmers should know this trick). I've
written the state monad implementation [1] and a set of combinators
[2] which includes [push], [nest],  [source] (a wrapper for
Basis.source) and [query] (a wrapper for Basis.query). Also there is a
[query_] which is a version of [query] returning {} instead of
[state]. See the code below for an example. Surprisingly for me, the
compiler accepts almost all of it, including [query_]. The only
combinator which doesn't compile is [query]. The error is:

    urweb -dbms sqlite ./test/XmlGen
    /home/grwlf/proj/urweb-monad-pack/state.ur:45:10: (to 48:39)
Anonymous function remains at code generation
    Function:
    (fn s : FFI(Basis.string) =>
      (fn _ : {} => {1 = UNBOUND_3, 2 = UNBOUND_2}))
    make[1]: *** [.fix-multy5] Error 1

Could you please check the implementation for errors and maybe suggest
changes necessary to make it work?

Regards,
Sergey

[1] - https://github.com/grwlf/urweb-monad-pack/blob/master/state.ur
(the implementation of state monad transformer)
[2] - https://github.com/grwlf/urweb-monad-pack/blob/master/test/XmlGen.ur
(the implementation of [query] and the test page)
[3] - https://github.com/grwlf/urweb-monad-pack (the whole project)


Example application code from XmlGen.ur:

...

structure MT = State.Trans(struct con m = Basis.transaction end)

...

fun viewm {} : transaction page =

  (x,i) <- MT.run <xml/> (

    s <- source False;

    push (<xml>Test1<br/></xml>);
    push (<xml>Test2<br/></xml>);

    nest (fn x => <xml><table>{x}</table></xml>) (
      push (<xml><tr><td>1</td><td>2</td></tr></xml>);
      push (<xml><tr><td>3</td><td>4</td></tr></xml>);
      return {}
    );

    (* Stateless query works! *)

    query_ (SELECT * FROM t) (fn r =>
      push (<xml><div>{[r.T.Id]}{[r.T.Nam]}</div><br/></xml>);
      return {}
    );

    (* Unfortunately, including state into query causes 'Anonymous
function remains' error *)

    n <- query (SELECT * FROM t) 0 (fn r i =>
      push (<xml><div>{[r.T.Id]}{[r.T.Nam]}</div></xml>);
      return (i+1)
    );

    return n
  );
  return <xml><body>{x} {[i]}</body></xml>

...



More information about the Ur mailing list