Discussion:
[Ur] SVG Test based on ListEdit.ur
Jonas Mellin
2018-05-01 22:04:48 UTC
Permalink
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>
Adam Chlipala
2018-05-01 22:59:14 UTC
Permalink
Yes, I'm sorry, but the <dyn> tag is only for HTML and the DOM.  It
would take extra implementation effort to make it compatible with SVG,
and that effort has not yet been made... so it's good that the compiler
is raising a static error!
Post by Jonas Mellin
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.
/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 = ()]
===== CODE =====
[...]
    <circle cx={show ((fst x')-60)} cy={show ((snd x')-100)} r="10"
stroke="red" fill="blue"/>
[...]
and show' (pl : plist) : signal xsvg   =
    case pl of
Nil => return <xml/>
| Cons {Point = p, Tail = t } => return <xml>
    <dyn signal={circleDraw p}/>
</xml>
Jonas Mellin
2018-05-02 00:35:24 UTC
Permalink
Hmm, so https://github.com/karsar/urweb-examples/blob/master/SVGTest/SVGTest.ur works because the SVG is encapsulated in HTML inside the dyn. That restricts the options for employing SVG.

/Jonas




From: Ur [mailto:ur-***@impredicative.com] On Behalf Of Adam Chlipala
Sent: den 2 maj 2018 00:59
To: ***@impredicative.com
Subject: Re: [Ur] SVG Test based on ListEdit.ur

Yes, I'm sorry, but the <dyn> tag is only for HTML and the DOM. It would take extra implementation effort to make it compatible with SVG, and that effort has not yet been made... so it's good that the compiler is raising a static error!

On 05/01/2018 06:04 PM, Jonas Mellin wrote:
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 = ()]

===== CODE =====
[...]
<circle cx={show ((fst x')-60)} cy={show ((snd x')-100)} r="10" stroke="red" fill="blue"/>
[...]

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

Loading...