[Ur] using mapX

Sergey Mironov grrwlf at gmail.com
Wed Oct 2 06:45:58 EDT 2013


Oh, I've moved one step further. Actually, my original attempt
requires reverse-engineering ability from the compiler. Here is the
xmlify which makes compiler happy:


(The difference is in first argument of mapX)

fun xmlify
  [ctx ::: {Unit}]
  [t ::: {Type}]
  (fl : folder (map (fn _ => xml ctx [] []) t))
  (r : record (map (fn _ => xml ctx [] []) t))
     : xml ctx [] [] =
    @mapX [fn _ => xml ctx [] []] [ctx]
      (fn [nm ::_] [t ::_] [r ::_] [[nm]~r] x => x)
        fl r

Unfortunately, when I try to apply it

val n : xbody = xmlify { A = <xml><p>asdasd</p></xml> }


I got another error:

dev:[grwlf at greyblade:~/proj/urdesign]$ urweb -dbms sqlite Test
/home/grwlf/proj/urdesign/Test.ur:131:0: (to 131:55) Some constructor
unification variables are undetermined in declaration
(look for them as "<UNIF:...>")
Decl:
val
 n : xbody =
  UNBOUND_NAMED915 [([Body = ()]) ++ [Dyn = (), MakeForm = ()]]
   [[A = <UNIF:U288::Type>]]
   Top.Folder.cons[[Type]] [[]] [#A]
    [xml ([Body = (), Dyn = (), MakeForm = ()]) ([]) ([])]
    Top.Folder.nil[[Type]]
   {A =
     Basis.tag [[]]
      [[Id = id, Title = string, Onblur = transaction {},
         Onfocus = transaction {}, Onclick = mouseEvent -> transaction unit,
         Ondblclick = mouseEvent -> transaction unit,
         Onmousedown = mouseEvent -> transaction unit,
         Onmousemove = mouseEvent -> transaction unit,
         Onmouseout = mouseEvent -> transaction unit,
         Onmouseover = mouseEvent -> transaction unit,
         Onmouseup = mouseEvent -> transaction unit,
         Onkeydown = keyEvent -> transaction unit,
         Onkeypress = keyEvent -> transaction unit,
         Onkeyup = keyEvent -> transaction unit, Onresize = transaction {},
         Onscroll = transaction {}]]
      [([Body = ()]) ++ [Dyn = (), MakeForm = ()]]
      [([Body = ()]) ++ [Dyn = (), MakeForm = ()]] [[]] [[]] [[]] [[]]
      Basis.null (Basis.None [signal css_class]) Basis.noStyle
      (Basis.None [signal css_style]) {} (p [[Dyn = (), MakeForm = ()]] {})
      (Basis.cdata [([Body = ()]) ++ [Dyn = (), MakeForm = ()]] [[]] "asdasd")}

What does it mean?

Regards,
Sergey


2013/10/2 Sergey Mironov <grrwlf at gmail.com>:
> Hi
>
> I've got trouble applying mapX (declared in top.urs). I want to
> translate a record filled with xml fields into one xml like this
>
> val all = xmlify { A = <xml><p>blabla</p></xml> , B = <xml><p>zzz</p></xml> }
>
> I know that potential problem is the order of visiting fields, but for
> now Its ok to have any of <xml>{r.A}{r.B}</xml> or
> <xml>{r.B}{r.A}</xml>
>
> I attempted to declare xmlify like that:
>
> fun xmlify
>   [ctx ::: {Unit}]
>   [t ::: {Type}]
>   (fl : folder (map (fn _ => xml ctx [] []) t))
>   (r : record (map (fn _ => xml ctx [] []) t))
>      : xml ctx [] [] =
>     @mapX [ident] [ctx]
>       (fn [nm ::_] [t ::_] [r ::_] [[nm]~r] x => x)
>         fl r
>
> Unfortunately, the compiler errors with
>
> dev:[grwlf at greyblade:~/proj/urdesign]$ urweb -dbms sqlite Test
> /home/grwlf/proj/urdesign/Test.ur:117:6: (to 117:51) Unification failure
> Expression:
> fn nm :: Name => fn t :: Type => fn r :: {Type} => fn x : t => x
>   Have con:
> nm :: Name -> t :: Type -> r :: {Type} -> [[nm = ()] ~ r] => t -> t
>   Need con:
> nm :: Name ->
>  t :: Type ->
>   rest :: {Type} -> [[nm = ()] ~ rest] => t -> xml ctx ([]) ([])
> Incompatible constructors
> Have:  t
> Need:  xml ctx ([]) ([])
>
> Looks like it doesn't think that all the fields of r (the input of
> xmlify) are really xmls, despite the fact that r's type is (map
> (fn_=>xml ctx [] []) t) . Am I correct in this conclusion? Can I
> bypass it?
>
> Regards,
> Sergey



More information about the Ur mailing list