From jonas.mellin at his.se Mon Apr 16 04:58:15 2018 From: jonas.mellin at his.se (Jonas Mellin) Date: Mon, 16 Apr 2018 08:58:15 +0000 Subject: [Ur] UR/Web SVG (ffi) question Message-ID: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> 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 = fun proc (x: intPair) = x <- source x; return set x (ev.ScreenX,ev.SceenY)}>
{circleDraw x} }/>
fun main(): transaction page = xml <- proc (0,0); return Banzai {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]) ++ ) -> 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: ++ [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: From adamc at csail.mit.edu Mon Apr 16 07:28:59 2018 From: adamc at csail.mit.edu (Adam Chlipala) Date: Mon, 16 Apr 2018 07:28:59 -0400 Subject: [Ur] UR/Web SVG (ffi) question In-Reply-To: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> References: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> Message-ID: <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> I have not read all of your code, but I did spot the problem behind the first compiler error message, which I think all web developers would agree is problematic. (I.e., it isn't just a question of a fussy Ur/Web type system.) On 04/16/2018 04:58 AM, Jonas Mellin wrote: > > fun proc (x: intPair) = > >     x <- source x; > >     return > >                               > >                                 set x > (ev.ScreenX,ev.SceenY)}> > > > >                                 > > fun main(): transaction page = > >     xml <- proc (0,0); > >     return > >                               > >                                 > >                                  Banzai > >                                 > >                                 > >                                  {xml} > >                                 > >                               > > [...] > > > /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 = ()] > Notice that your [proc] code includes a tag, but then you nest it within another tag! -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.mellin at his.se Tue Apr 17 05:53:32 2018 From: jonas.mellin at his.se (Jonas Mellin) Date: Tue, 17 Apr 2018 09:53:32 +0000 Subject: [Ur] UR/Web SVG (ffi) question In-Reply-To: <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> References: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> Message-ID: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5C672F@HSMSMBX1.hs.local> Thx. One trial, that I believe should work, is: open SVG (*con intPair = int*int*) fun fst (x: int*int) = x.1 fun snd (x: int*int) = x.2 fun circleDraw(x: int*int): xsvg = fun proc (x: int*int): transaction page = x <- source x; return set x (ev.ScreenX,ev.SceenY)}>
{circleDraw x} }/>
fun main(): transaction page = let val a = (0,0) in xml <- proc a; return Banzai {xml} end But I get: 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: ++ [ScreenX = int, SceenY = int] On " set x (ev.ScreenX,ev.SceenY)}>" From: Ur [mailto:ur-bounces at impredicative.com] On Behalf Of Adam Chlipala Sent: den 16 april 2018 13:29 To: ur at impredicative.com Subject: Re: [Ur] UR/Web SVG (ffi) question I have not read all of your code, but I did spot the problem behind the first compiler error message, which I think all web developers would agree is problematic. (I.e., it isn't just a question of a fussy Ur/Web type system.) On 04/16/2018 04:58 AM, Jonas Mellin wrote: [Jonas Mellin] <<< collapsed answer >>> Notice that your [proc] code includes a tag, but then you nest it within another tag! -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Tue Apr 17 07:19:40 2018 From: adamc at csail.mit.edu (Adam Chlipala) Date: Tue, 17 Apr 2018 07:19:40 -0400 Subject: [Ur] UR/Web SVG (ffi) question In-Reply-To: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5C672F@HSMSMBX1.hs.local> References: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5C672F@HSMSMBX1.hs.local> Message-ID: <5303d756-97f2-dc91-95f7-70a0618b050e@csail.mit.edu> For future questions, I think it would be good for you to explain what you understand from error messages, highlighting what additional understanding you need to diagnose the error.  Here again the problem is a simple one that would be recognized as a bug in any programming language. Notice the difference in spellings of field names, between the "Have" and "Need" parts of the error message. On 04/17/2018 05:53 AM, Jonas Mellin wrote: > ... > >   set x (ev.ScreenX,ev.SceenY)}> > > ... > > *But I get:*** > > 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: ++ [ScreenX = int, SceenY = int] > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.mellin at his.se Tue Apr 17 08:00:00 2018 From: jonas.mellin at his.se (Jonas Mellin) Date: Tue, 17 Apr 2018 12:00:00 +0000 Subject: [Ur] UR/Web SVG (ffi) question In-Reply-To: <5303d756-97f2-dc91-95f7-70a0618b050e@csail.mit.edu> References: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5C672F@HSMSMBX1.hs.local> <5303d756-97f2-dc91-95f7-70a0618b050e@csail.mit.edu> Message-ID: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5CA31E@HSMSMBX1.hs.local> My bad, sorry. It took me a short while to see the misspelling. Got it working. I will be more careful about that in the future. I move on to trying multiple objects and then adding "foreignObject" tag: val foreignObject : svgTag([X = string, Y = string, Width = string, Height = string] ++ typicalAttrs) an addition to the SVG.urs (cf. original at https://github.com/karsar/urweb-examples/blob/master/SVGTest/SVG.urs) , this require somehow to mix xsvg with xbody. Anything in particular that has to be taken into account when mixing this? /Jonas Mellin From: Ur [mailto:ur-bounces at impredicative.com] On Behalf Of Adam Chlipala Sent: den 17 april 2018 13:20 To: ur at impredicative.com Subject: Re: [Ur] UR/Web SVG (ffi) question For future questions, I think it would be good for you to explain what you understand from error messages, highlighting what additional understanding you need to diagnose the error. Here again the problem is a simple one that would be recognized as a bug in any programming language. Notice the difference in spellings of field names, between the "Have" and "Need" parts of the error message. On 04/17/2018 05:53 AM, Jonas Mellin wrote: ... set x (ev.ScreenX,ev.SceenY)}> ... But I get: 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: ++ [ScreenX = int, SceenY = int] -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Tue Apr 17 09:44:19 2018 From: adamc at csail.mit.edu (Adam Chlipala) Date: Tue, 17 Apr 2018 09:44:19 -0400 Subject: [Ur] UR/Web SVG (ffi) question In-Reply-To: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5CA31E@HSMSMBX1.hs.local> References: <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5A5486@HSMSMBX1.hs.local> <0e962318-4992-b3e9-d117-c32d74e9d8ed@csail.mit.edu> <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5C672F@HSMSMBX1.hs.local> <5303d756-97f2-dc91-95f7-70a0618b050e@csail.mit.edu> <67EBC36FAF00564EAAE9C7FD4E3CE3B0010D5CA31E@HSMSMBX1.hs.local> Message-ID: <6f426f67-c2d0-4d22-34e9-25d08e1d71ec@csail.mit.edu> I think it should all "just work," with your new tag added in an FFI .urs file like that! On 04/17/2018 08:00 AM, Jonas Mellin wrote: > > My bad, sorry. It took me a short while to see the misspelling. Got it > working. I will be more careful about that in the future. > > I move on to trying multiple objects and then adding “foreignObject” tag: > > val foreignObject : svgTag([X = string, Y = string, Width = string, > Height = string] ++ typicalAttrs) > > an addition to the SVG.urs (cf. original at > https://github.com/karsar/urweb-examples/blob/master/SVGTest/SVG.urs) > , this require somehow to mix xsvg with xbody. Anything in particular > that has to be taken into account when mixing this? > > /Jonas Mellin > > *From:*Ur [mailto:ur-bounces at impredicative.com] *On Behalf Of *Adam > Chlipala > *Sent:* den 17 april 2018 13:20 > *To:* ur at impredicative.com > *Subject:* Re: [Ur] UR/Web SVG (ffi) question > > For future questions, I think it would be good for you to explain what > you understand from error messages, highlighting what additional > understanding you need to diagnose the error. Here again the problem > is a simple one that would be recognized as a bug in any programming > language. > > Notice the difference in spellings of field names, between the "Have" > and "Need" parts of the error message. > > On 04/17/2018 05:53 AM, Jonas Mellin wrote: > > ... > >   set x (ev.ScreenX,ev.SceenY)}> > > ... > > *But I get:* > > 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: ++ [ScreenX = int, SceenY = int] > > > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur -------------- next part -------------- An HTML attachment was scrubbed... URL: