[Ur] UR/Web SVG (ffi) question

Jonas Mellin jonas.mellin at his.se
Mon Apr 16 04:58:15 EDT 2018


Dear all, I am a novice with respect to UR/Web and I want to use it together with SVG. I found the prototype ffi for SVG at https://github.com/karsar/urweb-examples/tree/master/SVGTest
 after reading through the material, doing all the tutorials and generally digging around internet.

Anyway, I took the example from https://github.com/karsar/urweb-examples/tree/master/SVGTest
 and tried to modify it; I fail repeatedly, so now I turn to this email list.

Instead of the SVGTest.ur that has all the functionality in main, I tried to break it out to a separate function "proc". I took the idea from http://www.impredicative.com/ur/demo/sql.html
 to generate an html page into a variable and then add that as return statement in the main function as seen below.

===== Modified SVGTest.ur with respect to https://github.com/karsar/urweb-examples/tree/master/SVGTest

open SVG

con intPair = int*int

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


fun proc (x: intPair) =
    x <- source x;
    return
                             <xml>
                               <body onmousemove={fn ev => set x (ev.ScreenX,ev.SceenY)}>
                                 <div style="width:800; heigth:800">
                                   <dyn signal={x<-signal x;
                                                                                          return
                                                                                              <xml>
                                                                                                                     <svg width="800" height="800">
                                                                                                                       {circleDraw x}
                                                                                                                     </svg>
                                                                                              </xml>}/>
                                                                                                                          </div>
                                 </body>
                               </xml>



fun main(): transaction page =
    xml <- proc (0,0);
    return
                             <xml>
                               <head>
                                 Banzai
                               </head>
                               <body>
                                 {xml}
                               </body>
                             </xml>




I have tried different options (e.g., that the proc should return transaction page, xbody, xsvg) and I fail in different ways. (I tried to add other functionality initially, but I removed it to try to get to the bottom of the problem).

The compiler tells me:



urweb SVGTest
/home/a/SVGTest2/SVGTest.ur:33:4: (to 44:2) Error in final record unification
Can't unify record constructors
Have:  [Dyn = (), MakeForm = (), Body = ()]
Need:  [Html = ()]
/home/a/SVGTest2/SVGTest.ur:33:4: (to 44:2) Stuck unifying these records after canceling matching pieces:
Have:  [Dyn = (), MakeForm = (), Body = ()]
Need:  [Html = ()]
/home/a/SVGTest2/SVGTest.ur:17:7: (to 17:64) Error in final record unification
Can't unify record constructors
   Have:
[Data = data_attr, Onload = transaction {},
  Onresize = transaction {}, Onunload = transaction {},
  Onhashchange = transaction {},
  [<<< REMOVED to reduce size of message>>>]
Value 1:
{ScreenX : int, ScreenY : int, ClientX : int, ClientY : int,
  CtrlKey : bool, ShiftKey : bool, AltKey : bool, MetaKey : bool,
  Button : mouseButton} -> transaction {}
Value 2:
$(([ScreenX = int, SceenY = int]) ++ <UNIF:U141::{Type}>) ->
 transaction {}
Can't unify record constructors
Have:
[ScreenX = int, ScreenY = int, ClientX = int, ClientY = int,
  CtrlKey = bool, ShiftKey = bool, AltKey = bool, MetaKey = bool,
  Button = mouseButton]
Need:  <UNIF:U141::{Type}> ++ [ScreenX = int, SceenY = int]

Compilation exited abnormally with code 1 at Wed Apr 11 08:45:06

Thanks in advance, Jonas Mellin, Senior Lecturer, University of Skövde



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


More information about the Ur mailing list