[Ur] SVG Test based on ListEdit.ur

Jonas Mellin jonas.mellin at his.se
Tue May 1 18:04:48 EDT 2018


Dear all, I have tried to adapt ListEdit.ur in the tutorial to a small SVG application that adds circles to the screen as you double click (the code is at the end). The SVG.urs is found at https://github.com/karsar/urweb-examples/blob/master/SVGTest/SVG.urs

I get a problem at row 57 "<dyn signal={circleDraw p}/>" and also at line 22 "show' (pl : plist) : signal xsvg   =" where the compiler gets stuck on "Error in final record unification
Can't unify record constructors". My hypothesis is that there is some problem between html and SVG.

An excerpt of the error messages sis:
/home/a/SVGTest5/SVGTest.ur:57:3: (to 58:8) Error in final record unification
Can't unify record constructors
Have:  <UNIF:U571::{Unit}> ++ [Dyn = ()]
Need:  [Svg = ()]
/home/a/SVGTest5/SVGTest.ur:57:3: (to 58:8) Stuck unifying these records after canceling matching pieces:
Have:  ([Dyn = ()]) ++ <UNIF:U571::{Unit}>
Need:  [Svg = ()]
/home/a/SVGTest5/SVGTest.ur:57:10: (to 57:30) Error in final record unification
Can't unify record constructors
   Have:
[Signal =
  signal (xml (([Dyn = ()]) ++ <UNIF:U571::{Unit}>) ([]) ([]))]
   Need:
<UNIF:U550::{Type}> ++ [Signal = signal (xml ([Svg = ()]) ([]) ([]))]
  Field:  #Signal
Value 1:
signal (xml (([Dyn = ()]) ++ <UNIF:U571::{Unit}>) ([]) ([]))
Value 2:  signal (xml ([Svg = ()]) ([]) ([]))
Can't unify record constructors
Have:  <UNIF:U571::{Unit}> ++ [Dyn = ()]
Need:  [Svg = ()]
/home/a/SVGTest5/SVGTest.ur:22:10: (to 22:22) Error in final record unification
Can't unify record constructors
Have:  <UNIF:U168::{Unit}> ++ [Dyn = ()]
Need:  [Svg = ()]
/home/a/SVGTest5/SVGTest.ur:22:10: (to 22:22) Stuck unifying these records after canceling matching pieces:
Have:  ([Dyn = ()]) ++ <UNIF:U168::{Unit}>
Need:  [Svg = ()]
/home/a/SVGTest5/SVGTest.ur:26:9: (to 26:35) Error in final record unification
Can't unify record constructors
   Have:
[Signal =
  signal (xml (([Dyn = ()]) ++ <UNIF:U168::{Unit}>) ([]) ([]))]
   Need:
<UNIF:U147::{Type}> ++ [Signal = signal (xml ([Svg = ()]) ([]) ([]))]
  Field:  #Signal
Value 1:
signal (xml (([Dyn = ()]) ++ <UNIF:U168::{Unit}>) ([]) ([]))
Value 2:  signal (xml ([Svg = ()]) ([]) ([]))
Can't unify record constructors
Have:  <UNIF:U168::{Unit}> ++ [Dyn = ()]
Need:  [Svg = ()]


===== CODE =====
open SVG

datatype plist = Nil | Cons of {Point : source (int*int),
                                                                                                                    Tail: source plist}

(*con intPair = int*int*)

fun fst (x: int*int) = x.1
fun snd (x: int*int) = x.2
fun circleDraw x : signal xsvg  =
    x' <- signal x;
    return
                             <xml>
                                 <circle cx={show ((fst x')-60)} cy={show ((snd x')-100)} r="10" stroke="red" fill="blue"/>
                             </xml>


fun show (pl: source plist) : signal xsvg   =
    pl <- signal pl;
    show' pl

and show' (pl : plist) : signal xsvg   =
    case pl of
                             Nil => return <xml/>
                             | Cons {Point = p, Tail = t } => return <xml>
                                 <dyn signal={circleDraw p}/>
                             </xml>



fun proc () =
    l <- source Nil;
    tailP <- source l;
    point <- source (0,0);
    let
                             fun add () =
                                 p <- get point;
                                 p' <- source p;
                                 tail <- get tailP;
                                 tail' <- source Nil;
                                 let
                                                          val cons = Cons {Point = p', Tail = tail'}
                                 in
                                                          set tail cons;
                                                          set tailP tail';
                                                          l' <- get l;
                                                          case l' of
                                                              Nil => set l cons
                                                            | _ => return ()
                                 end
    in
                             return
                                 <xml>
                                   <body ondblclick={fn ev => set point (ev.ScreenX,ev.ScreenY); add()}>
                                                          <div style="width:800; heigth:800">
                                                            <svg width="800" height="600">
                                                              <dyn signal={show l}/>
                                                            </svg>
                                                          </div>
                                   </body>
            </xml>
    end


fun main()  =
    xml <- proc ();
    return
                             <xml>
                               <head>
                                 Banzai
                               </head>
                                 {xml}
                             </xml>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20180501/83da3d01/attachment-0001.html>


More information about the Ur mailing list