From yves.cloutier at gmail.com Fri Apr 1 20:31:14 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Fri, 1 Apr 2016 20:31:14 -0400 Subject: [Ur] Sequences Message-ID: Hello, I would like to refactor some code to use a sequence instead of manually incrementing a counter to serve as a unique db table index. Following an example, I simply did: ... sequence expId ... Then when I want to increment: ... nextId <- nextval expId; ... I recompile, but when I execute I get the following error: Fatal initialization error: Sequence 'uw_Portfolipro_expId' does not exist. IS there something else that I need to do, create or initialise in order to use sequences? Below is my full code: table experienceTable : { Id : int, Description : string} PRIMARY KEY Id sequence expId fun refresh () = rows <- queryX (SELECT * FROM experienceTable) (fn row => {[row.ExperienceTable.Id]} {[row.ExperienceTable.Description]}
); return {rows}
Id Description



Description:
(* Add a new experience *) and addExperience experience = nextId <- nextval expId; dml (INSERT INTO experienceTable (Id, Description) VALUES ({[nextId]}, {[readError experience.Description]})); page <- refresh (); return {page} (* Delete a given experience *) and deleteExperience experienceId () = dml (DELETE FROM experienceTable WHERE t.Id = {[experienceId]}); page <- refresh (); return {page} fun main () = content <- refresh (); return {content} -------------- next part -------------- An HTML attachment was scrubbed... URL: From ziv at mit.edu Sat Apr 2 03:07:19 2016 From: ziv at mit.edu (Ziv Scully) Date: Sat, 2 Apr 2016 03:07:19 -0400 Subject: [Ur] Sequences In-Reply-To: References: Message-ID: Same again: you need to run the generated SQL script (like last time) to create the sequence in the database. In general, you need to do this whenever your table/sequence schema changes. In the case where you just add tables or sequences, running the SQL file again suffices. If you've modified the layout of a table, you might need to manually drop the table first. If you want to modify a table while keeping the existing data... well, I'm sure there's a way, but I don't know what it is. On Friday, April 1, 2016, Yves Cloutier wrote: > Hello, > > I would like to refactor some code to use a sequence instead of manually > incrementing a counter to serve as a unique db table index. > > Following an example, I simply did: > > ... > sequence expId > ... > > Then when I want to increment: > > ... > nextId <- nextval expId; > ... > > I recompile, but when I execute I get the following error: > > Fatal initialization error: Sequence 'uw_Portfolipro_expId' does not exist. > > IS there something else that I need to do, create or initialise in order > to use sequences? > > Below is my full code: > > table experienceTable : { Id : int, Description : string} > PRIMARY KEY Id > > sequence expId > > fun refresh () = > rows <- queryX (SELECT * FROM experienceTable) > (fn row => > {[row.ExperienceTable.Id]} > {[row.ExperienceTable.Description]} >
row.ExperienceTable.Id} value="Delete"/> >
); > return > > > {rows} >
Id Description
> >


> >
> > > > >
Description:
>
>
> > (* Add a new experience *) > and addExperience experience = > nextId <- nextval expId; > dml (INSERT INTO experienceTable (Id, Description) > VALUES ({[nextId]}, {[readError experience.Description]})); > page <- refresh (); > return > {page} > > > (* Delete a given experience *) > and deleteExperience experienceId () = > dml (DELETE FROM experienceTable > WHERE t.Id = {[experienceId]}); > page <- refresh (); > return > {page} > > > fun main () = > content <- refresh (); > return > {content} > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Sat Apr 2 07:31:04 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Sat, 2 Apr 2016 07:31:04 -0400 Subject: [Ur] Sequences In-Reply-To: References: Message-ID: <56FFAD78.6000306@csail.mit.edu> On 04/02/2016 03:07 AM, Ziv Scully wrote: > If you've modified the layout of a table, you might need to > manually drop the table first. If you want to modify a table > while keeping the existing data... well, I'm sure there's a way, but I > don't know what it is. Standard "ALTER TABLE" commands get the job done there. From yves.cloutier at gmail.com Sat Apr 2 11:16:23 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Sat, 2 Apr 2016 11:16:23 -0400 Subject: [Ur] Sequences Message-ID: Hi Ziv, Yes I managed to figure that out soon after i posted. I actually started off by dopping the db and recreated it. But ended up running psql -f portfolipro.sql portfolipro and that's where I saw some output on the console: CREATE TABLE CREATE SEQUENCE Actually i wasn't able to drop the db on my first try. It seemed that there were a couple of instances of my application still running. I needed to find and kill them first before i could drop it. I must not be closing my application properly, since on other occassions when I would recompile and run again, it won't start on port 8080, and i need to specify another port, like 8081. yc -------------- next part -------------- An HTML attachment was scrubbed... URL: From yves.cloutier at gmail.com Sat Apr 2 15:54:04 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Sat, 2 Apr 2016 15:54:04 -0400 Subject: [Ur] Editor Syntax Highlighting, Indentation Message-ID: Hello, I'm currently using Kate w/ the SML syntax highlighting, but I have been wondering if there are better editors for writing urweb code. I know vim or emacs are favorites among developers. Is this what most of you here use? If so, and if you have made some configs for writing code and how it's displayed (syntax highlighting, indentation etc), would you be willing to share your config files with us? Regards, and thanks as always. As you probably noticed I'm not as experienced as others may be, and it's nice to be able to ask questions and not feel embarrassed about it. The folks on this group are very helpful. yc -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Sat Apr 2 16:00:45 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Sat, 2 Apr 2016 16:00:45 -0400 Subject: [Ur] Editor Syntax Highlighting, Indentation In-Reply-To: References: Message-ID: <570024ED.1080802@csail.mit.edu> Ur/Web is distributed with an official Emacs mode. On 04/02/2016 03:54 PM, Yves Cloutier wrote: > Hello, > > I'm currently using Kate w/ the SML syntax highlighting, but I have > been wondering if there are better editors for writing urweb code. I > know vim or emacs are favorites among developers. > > Is this what most of you here use? If so, and if you have made some > configs for writing code and how it's displayed (syntax highlighting, > indentation etc), would you be willing to share your config files with us? > > Regards, and thanks as always. As you probably noticed I'm not as > experienced as others may be, and it's nice to be able to ask > questions and not feel embarrassed about it. > > The folks on this group are very helpful. > > yc From foldr at tutanota.com Sun Apr 3 22:24:50 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Mon, 4 Apr 2016 03:24:50 +0100 (BST) Subject: [Ur] Error handling in Ur Message-ID: Hi all, How do I handle application errors in Ur? Is there a preferred method which allows to check whether all errors have their handlers or not? I am looking for maybe something similar to the below: http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From grrwlf at gmail.com Mon Apr 4 05:15:54 2016 From: grrwlf at gmail.com (Sergey Mironov) Date: Mon, 4 Apr 2016 12:15:54 +0300 Subject: [Ur] Error handling in Ur In-Reply-To: References: Message-ID: Hi! Without pretending to answer your question completely, could you please take a look at https://github.com/grwlf/urweb-monad-pack (error.ur) ? Regards, Sergey 2016-04-04 5:24 GMT+03:00 : > Hi all, > > How do I handle application errors in Ur? Is there a preferred method which > allows to check whether all errors have their handlers or not? > > I am looking for maybe something similar to the below: > http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > From adamc at csail.mit.edu Mon Apr 4 05:48:14 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Mon, 4 Apr 2016 05:48:14 -0400 Subject: [Ur] Error handling in Ur In-Reply-To: References: Message-ID: <5702385E.4020100@csail.mit.edu> The idiomatic approach is just to call the [error] function to end execution, with an error message. On 04/03/2016 10:24 PM, foldr at tutanota.com wrote: > Hi all, > > How do I handle application errors in Ur? Is there a preferred method > which allows to check whether all errors have their handlers or not? > > I am looking for maybe something similar to the below: > http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From foldr at tutanota.com Mon Apr 4 06:01:05 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Mon, 4 Apr 2016 11:01:05 +0100 (BST) Subject: [Ur] Error handling in Ur In-Reply-To: References: <> Message-ID: Sergey, thanks for the suggestion. I've just started to implement something very similar today. Your version seems to be better and more complete. 4. Apr 2016 21:15 by grrwlf at gmail.com: > Hi! Without pretending to answer your question completely, could you > please take a look at > https://github.com/grwlf/urweb-monad-pack > (error.ur) ? > > Regards, > Sergey > > 2016-04-04 5:24 GMT+03:00 <> foldr at tutanota.com> >: >> Hi all, >> >> How do I handle application errors in Ur? Is there a preferred method >> which >> allows to check whether all errors have their handlers or not? >> >> I am looking for maybe something similar to the below: >> http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html >> >> _______________________________________________ >> Ur mailing list >> Ur at impredicative.com >> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur >> > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur -------------- next part -------------- An HTML attachment was scrubbed... URL: From foldr at tutanota.com Mon Apr 4 06:49:18 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Mon, 4 Apr 2016 11:49:18 +0100 (BST) Subject: [Ur] Error handling in Ur In-Reply-To: <5702385E.4020100@csail.mit.edu> References: <> <5702385E.4020100@csail.mit.edu> Message-ID: Adam, I thought that [error] could be used as the last resort - when something severe happens. What would be the right approach to get rid of multiple enclosed case/if statements? Imagine user input validation in a complex data entry form - all data inconsistencies produce different error messages and all require form resubmission. The code at [1] would be an example of how such error handling could be rewritten, but I would like to declare multiple error types and pattern match them. [1] https://github.com/grwlf/urweb-monad-pack/blob/master/test/TestError1.ur 4. Apr 2016 21:48 by adamc at csail.mit.edu: > The idiomatic approach is just to call the [error] function to end > execution, with an error message. > > > On 04/03/2016 10:24 PM, > foldr at tutanota.com> wrote: > > >> >> Hi all, >> >> How do I handle application errors in Ur? Is there a preferred >> method which allows to check whether all errors have their >> handlers or not? >> >> I am looking for maybe something similar to the below: >> >> >> http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Mon Apr 4 17:21:53 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Mon, 4 Apr 2016 17:21:53 -0400 Subject: [Ur] Error handling in Ur In-Reply-To: References: < <5702385E.4020100@csail.mit.edu> Message-ID: <5702DAF1.603@csail.mit.edu> There's no standard way of doing such things, beyond the tenuously connected example of the [option] monad. "urweb-monad-pack" may indeed be the best starting point. On 04/04/2016 06:49 AM, foldr at tutanota.com wrote: > Adam, I thought that [error] could be used as the last resort - when > something severe happens. > > What would be the right approach to get rid of multiple enclosed > case/if statements? Imagine user input validation in a complex data > entry form - all data inconsistencies produce different error messages > and all require form resubmission. The code at [1] would be an example > of how such error handling could be rewritten, but I would like to > declare multiple error types and pattern match them. > > [1] > https://github.com/grwlf/urweb-monad-pack/blob/master/test/TestError1.ur > > > > 4. Apr 2016 21:48 by adamc at csail.mit.edu : > > The idiomatic approach is just to call the [error] function to end > execution, with an error message. > > On 04/03/2016 10:24 PM, foldr at tutanota.com wrote: > > Hi all, > > How do I handle application errors in Ur? Is there a preferred > method which allows to check whether all errors have their > handlers or not? > > I am looking for maybe something similar to the below: > http://sylvain-henry.info/home/posts/2016-03-18-first-experiments-with-dependent-types.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From foldr at tutanota.com Tue Apr 5 07:56:28 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Tue, 5 Apr 2016 12:56:28 +0100 (BST) Subject: [Ur] FFI - initialization and shutdown logic for third-party modules Message-ID: Hi, Is there any mechanism to reliably initialize a third-party library on Ur/Web application startup and de-initialize it (once only!) on application shutdown? I probably can use [initialize] task in the beginning, but I need to ensure that it completes before any requests are processed by the application - can I rely on that? I have not found anything similar for shutdown de-initialization. See [1] for a practical example (notes at the bottom of the page). https://downloads.haskell.org/~ghc/7.10.3/docs/html/users_guide/ffi-ghc.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Tue Apr 5 08:32:26 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Tue, 5 Apr 2016 08:32:26 -0400 Subject: [Ur] FFI - initialization and shutdown logic for third-party modules In-Reply-To: References: Message-ID: <5703B05A.9080102@csail.mit.edu> On 04/05/2016 07:56 AM, foldr at tutanota.com wrote: > Is there any mechanism to reliably initialize a third-party library on > Ur/Web application startup and de-initialize it (once only!) on > application shutdown? > > I probably can use [initialize] task in the beginning, but I need to > ensure that it completes before any requests are processed by the > application - can I rely on that? Yes, it's guaranteed that [initialize] task code finishes before any requests are handled. > I have not found anything similar for shutdown de-initialization. No one asked for that kind of task yet, but it might not be too hard to add. -------------- next part -------------- An HTML attachment was scrubbed... URL: From yves.cloutier at gmail.com Wed Apr 6 19:31:29 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Wed, 6 Apr 2016 19:31:29 -0400 Subject: [Ur] Length mismatch in INSERT field specification Message-ID: Hello, I'm getting an error using a dml statement which I *can't* figure out: Length mismatch in INSERT field specification (4 vs. 3) I'm not sure why as the number of fields in my table definition are the same as the ones in my INSERT satement: table tblEmployers : {Id: int, Description: string, From: time, To: time} fun add r = nextid <- nextval uidEmployer; dml(INSERT INTO tblEmployers (Id, Description, From, To) VALUES ({[nextid]}, {[r.Description]}, {[r.From]}, {[r.To]})); Is there something obvious that I'm not seeing? Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Thu Apr 7 16:26:45 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Thu, 7 Apr 2016 16:26:45 -0400 Subject: [Ur] Length mismatch in INSERT field specification In-Reply-To: References: Message-ID: <5706C285.5040703@csail.mit.edu> Yes, there is something "obvious": that final semicolon shouldn't be there. Sorry for the suboptimal error message; yacc diagnostics are notoriously tricky! On 04/06/2016 07:31 PM, Yves Cloutier wrote: > Hello, > > I'm getting an error using a dml statement which I *can't* figure out: > > Length mismatch in INSERT field specification (4 vs. 3) > > I'm not sure why as the number of fields in my table definition are > the same as the ones in my INSERT satement: > > table tblEmployers : {Id: int, Description: string, From: time, To: time} > > fun add r = nextid <- nextval uidEmployer; > dml(INSERT INTO tblEmployers (Id, Description, > From, To) > VALUES ({[nextid]}, {[r.Description]}, > {[r.From]}, {[r.To]})); > > Is there something obvious that I'm not seeing? > > Thank you! From yves.cloutier at gmail.com Thu Apr 7 16:55:46 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Thu, 7 Apr 2016 16:55:46 -0400 Subject: [Ur] Length mismatch in INSERT field specification Message-ID: Thanks so much Adam. I was was basing my code on the example in Fig. 1 A simple chat-room application which had a ; ending the dml function call: fun say r = dml (INSERT INTO message (Room,When,Text) VALUES ({[id]},CURRENT_TIMESTAMP, {[r.Text]})); Is there a difference between them which justifies adding a ; in one case, but not the other? thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Thu Apr 7 17:06:31 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Thu, 7 Apr 2016 17:06:31 -0400 Subject: [Ur] Length mismatch in INSERT field specification In-Reply-To: References: Message-ID: <5706CBD7.30000@csail.mit.edu> In Ur/Web, semicolon is a separator, not a terminator. On 04/07/2016 04:55 PM, Yves Cloutier wrote: > Thanks so much Adam. I was was basing my code on the example in Fig. > 1 A simple chat-room application which had a ; ending the dml function > call: > > fun say r = > dml (INSERT INTO message (Room,When,Text) > VALUES ({[id]},CURRENT_TIMESTAMP, {[r.Text]})); > > Is there a difference between them which justifies adding a ; in one > case, but not the other? -------------- next part -------------- An HTML attachment was scrubbed... URL: From yves.cloutier at gmail.com Sat Apr 9 09:18:13 2016 From: yves.cloutier at gmail.com (Yves Cloutier) Date: Sat, 9 Apr 2016 09:18:13 -0400 Subject: [Ur] This is an expression but not a pattern Message-ID: Hello, regarding forms, what is the signature of r for the record that is passed to the handler function? I am trying to do something like: I have defined a module below for the purpose, but compiling gives an error pointing at the following line: val getList = queryL1 (SELECT * FROM tblEmployers) for which I have defined the signature to be: val getList: transaction (list {Id : int, Description : string, From : string, To : string}) Following the example in Fig 1 of Ur/Web: A Simple Model for Programming the Web. I do think this is fine, but that maybe the error is for the next function: val add: unit -> transaction unit Who's purpose is to be the handler for a form submit. After looking at the manual, basis.ur and top.ur, I am still not certain which type r (the record created by submitting a form). If someone could give me a tip that would great. Below is the full code for my module. structure Employers: sig (* Function that returns a list of employers from table tblEmployers *) val getList: transaction (list {Id : int, Description : string, From : string, To : string}) (* A handler for "Add Employer" form button *) val add: unit -> transaction unit (* Function that takes a employer ID and removes it from table tblEmployers *) val remove: int -> transaction unit end = struct (* A sequence to generate unique employer ID *) sequence uidEmployer (* A table of employers *) table tblEmployers : {Id: int, Description: string, From: time, To: time} val getList = queryL1 (SELECT * FROM tblEmployers) fun add r = val nextId = nextval uidEmployer dml (INSERT INTO tblEmployers (Id, Description, From, To) VALUES ({[nextId]}, {[r.Description]}, {[r.From]}, {[r.To]})) fun remove uidEmployer = dml (DELETE * FROM tblEmployers WHERE t.Id = {[uidEmployer.Id]}) end -------------- next part -------------- An HTML attachment was scrubbed... URL: From artyom.shalkhakov at gmail.com Sat Apr 9 10:16:43 2016 From: artyom.shalkhakov at gmail.com (Artyom Shalkhakov) Date: Sat, 9 Apr 2016 20:16:43 +0600 Subject: [Ur] This is an expression but not a pattern In-Reply-To: References: Message-ID: Hello Yves, 2016-04-09 19:18 GMT+06:00 Yves Cloutier : > Hello, regarding forms, what is the signature of r for the record that is > passed to the handler function? > > I am trying to do something like: > > > > I have defined a module below for the purpose, but compiling gives an error > pointing at the following line: > > val getList = queryL1 (SELECT * FROM tblEmployers) > > > for which I have defined the signature to be: > > val getList: transaction (list {Id : int, Description : string, From : > string, To : string}) > > Following the example in Fig 1 of Ur/Web: A Simple Model for Programming the > Web. > > I do think this is fine, but that maybe the error is for the next function: > > val add: unit -> transaction unit > The type of parameter should not be a [unit]. Try something like: > val add : {Description:string,From:string} -> transaction unit And the form should mention the names [Description] and [From]. Like in the example: > > Who's purpose is to be the handler for a form submit. After looking at the > manual, basis.ur and top.ur, I am still not certain which type r (the record > created by submitting a form). > > If someone could give me a tip that would great. Below is the full code for > my module. > > structure Employers: sig > > (* Function that returns a list of employers from table tblEmployers *) > val getList: transaction (list {Id : int, Description : string, From : > string, To : string}) > > (* A handler for "Add Employer" form button *) > val add: unit -> transaction unit > > (* Function that takes a employer ID and removes it from table > tblEmployers *) > val remove: int -> transaction unit > end = struct > > (* A sequence to generate unique employer ID *) > sequence uidEmployer > > (* A table of employers *) > table tblEmployers : {Id: int, Description: string, From: time, To: time} > > val getList = queryL1 (SELECT * FROM tblEmployers) > > fun add r = val nextId = nextval uidEmployer > dml (INSERT INTO tblEmployers (Id, Description, From, To) > VALUES ({[nextId]}, {[r.Description]}, {[r.From]}, > {[r.To]})) > > fun remove uidEmployer = dml (DELETE * FROM tblEmployers WHERE t.Id = > {[uidEmployer.Id]}) > end > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > -- Cheers, Artyom Shalkhakov From artyom.shalkhakov at gmail.com Thu Apr 14 06:53:56 2016 From: artyom.shalkhakov at gmail.com (Artyom Shalkhakov) Date: Thu, 14 Apr 2016 16:53:56 +0600 Subject: [Ur] C type for Ur/Web list type Message-ID: Hello all, I'd like to implement a function having the following type: > val join : list string -> option string -> string which would work as follows: - if second argument is Some, then it's taken as a separator - otherwise, it's assumed that no separator is necessary - the list of strings is concatenated into one contiguous string, with the separator inserted between the consecutive list elements For instance: > join [] _(*anything*) ==> "" > join ["a","b"] None ==> "ab" > join ["1","2"] (Some ",") ==> "1,2" I'd like to use C for implementation, and there is this question: what C types do [list string] and [option string] map to? I think that [option string] probably maps to a nullable pointer to uw_Basis_string. What about the list constructor? -- Cheers, Artyom Shalkhakov From adamc at csail.mit.edu Thu Apr 14 07:02:24 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Thu, 14 Apr 2016 07:02:24 -0400 Subject: [Ur] C type for Ur/Web list type In-Reply-To: References: Message-ID: <570F78C0.4010500@csail.mit.edu> On 04/14/2016 06:53 AM, Artyom Shalkhakov wrote: > there is this question: what C types do [list string] and [option > string] map to? I think that [option string] probably maps to a > nullable pointer to uw_Basis_string. What about the list constructor? That's a tricky one. There is actually no support for parametric polymorphism in the FFI. Every [list a] type is compiled to a separate C struct. From artyom.shalkhakov at gmail.com Thu Apr 14 07:14:58 2016 From: artyom.shalkhakov at gmail.com (Artyom Shalkhakov) Date: Thu, 14 Apr 2016 17:14:58 +0600 Subject: [Ur] C type for Ur/Web list type In-Reply-To: <570F78C0.4010500@csail.mit.edu> References: <570F78C0.4010500@csail.mit.edu> Message-ID: 2016-04-14 17:02 GMT+06:00 Adam Chlipala : > On 04/14/2016 06:53 AM, Artyom Shalkhakov wrote: >> >> there is this question: what C types do [list string] and [option string] >> map to? I think that [option string] probably maps to a nullable pointer to >> uw_Basis_string. What about the list constructor? > > > That's a tricky one. There is actually no support for parametric > polymorphism in the FFI. Every [list a] type is compiled to a separate C > struct. > Okay. The use-case is this: I'm decoding/encoding URI parameters in an Ur/Web program, naively. That involves a lot of string concatenation. Is there another (preferably external-dependency-free) approach to this? > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur -- Cheers, Artyom Shalkhakov From adamc at csail.mit.edu Thu Apr 14 07:24:17 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Thu, 14 Apr 2016 07:24:17 -0400 Subject: [Ur] C type for Ur/Web list type In-Reply-To: References: <570F78C0.4010500@csail.mit.edu> Message-ID: <570F7DE1.9070905@csail.mit.edu> On 04/14/2016 07:14 AM, Artyom Shalkhakov wrote: > 2016-04-14 17:02 GMT+06:00 Adam Chlipala : >> On 04/14/2016 06:53 AM, Artyom Shalkhakov wrote: >>> there is this question: what C types do [list string] and [option string] >>> map to? I think that [option string] probably maps to a nullable pointer to >>> uw_Basis_string. What about the list constructor? >> >> That's a tricky one. There is actually no support for parametric >> polymorphism in the FFI. Every [list a] type is compiled to a separate C >> struct. >> > Okay. The use-case is this: I'm decoding/encoding URI parameters in an > Ur/Web program, naively. That involves a lot of string concatenation. > Is there another (preferably external-dependency-free) approach to > this? Have you tried using normal Ur/Web code for that operation? I think there's a nontrivial chance that you'll get better performance that way than with C FFI code, because the compiler has special optimizations for string concatenation. They kick in when that concatenation flows directly into the value that is being returned as the HTTP body, whether it's HTML or a string in a blob. It's probably possible to get those optimizations into play in other situations, too, with a moderate amount of compiler work. From artyom.shalkhakov at gmail.com Thu Apr 14 07:35:21 2016 From: artyom.shalkhakov at gmail.com (Artyom Shalkhakov) Date: Thu, 14 Apr 2016 17:35:21 +0600 Subject: [Ur] C type for Ur/Web list type In-Reply-To: <570F7DE1.9070905@csail.mit.edu> References: <570F78C0.4010500@csail.mit.edu> <570F7DE1.9070905@csail.mit.edu> Message-ID: 2016-04-14 17:24 GMT+06:00 Adam Chlipala : > On 04/14/2016 07:14 AM, Artyom Shalkhakov wrote: >> >> 2016-04-14 17:02 GMT+06:00 Adam Chlipala : >>> >>> On 04/14/2016 06:53 AM, Artyom Shalkhakov wrote: >>>> >>>> there is this question: what C types do [list string] and [option >>>> string] >>>> map to? I think that [option string] probably maps to a nullable pointer >>>> to >>>> uw_Basis_string. What about the list constructor? >>> >>> >>> That's a tricky one. There is actually no support for parametric >>> polymorphism in the FFI. Every [list a] type is compiled to a separate C >>> struct. >>> >> Okay. The use-case is this: I'm decoding/encoding URI parameters in an >> Ur/Web program, naively. That involves a lot of string concatenation. >> Is there another (preferably external-dependency-free) approach to >> this? > > > Have you tried using normal Ur/Web code for that operation? I think there's > a nontrivial chance that you'll get better performance that way than with C > FFI code, because the compiler has special optimizations for string > concatenation. They kick in when that concatenation flows directly into the > value that is being returned as the HTTP body, whether it's HTML or a string > in a blob. > The code is as follows: > fun > uri_encode (s:string):string = let > fun > tohexstr i = let > val low = i % 16 > val high = i / 16 > fun hexdigit i = > case i of > 0 => "0" | 1 => "1" | 2 => "2" | 3 => "3" | 4 => "4" | 5 => "5" | 6 => "6" | 7 => "7" | 8 => "8" | 9 => "9" > | 10 => "A" | 11 => "B" | 12 => "C" | 13 => "D" | 14 => "E" | 15 => "F" > | _ => error tohexstr: invalid digit {[i]} > in > hexdigit high ^ hexdigit low > end > > fun > aux i n s acc = > if i < n then let > val c = strsub s i > in > (* NOTE: strcat seems to be QUITE inefficient here *) > if isalnum c || Option.isSome (String.index ";,/?:@&=+$#" c) then > aux (i+1) n s (strcat acc (str1 c)) > else > aux (i+1) n s (strcat acc (strcat "%" (tohexstr (ord c)))) > end > else acc > val res = aux 0 (strlen s) s "" > in > res > end > > fun > uri_decode (s: string): string = let > fun > aux i n s acc = > if i < n then let > val c = strsub s i > in > (* NOTE: strcat seems to be QUITE inefficient here *) > if c = #"%" then ( > if i+1 >= n || i+2 >= n then error decode: premature EOS > else let > val c1 = strsub s (i+1) > val c2 = strsub s (i+2) > val digit1 = > if c1 >= #"a" && c1 <= #"f" then ord c1 - ord #"a" + 10 > else if c1 >= #"A" && c1 <= #"F" then ord c1 - ord #"A" + 10 > else ord c1 - ord #"0" > val digit2 = > if c2 >= #"a" && c2 <= #"f" then ord c2 - ord #"a" + 10 > else if c2 >= #"A" && c2 <= #"F" then ord c2 - ord #"A" + 10 > else ord c2 - ord #"0" > val c0 = chr (digit1 * 16 + digit2) > in > aux (i+3) n s (strcat acc (str1 c0)) > end > ) > else if c = #"+" then aux (i+1) n s (strcat acc " ") > else aux (i+1) n s (strcat acc (str1 c)) > end > else acc > in > aux 0 (strlen s) s "" > end It seems to work fine in my tests. I'm just worried that concatenating strings this way is inefficient (I haven't actually looked at the generated code yet). I will take a look at the generated C code and get back here with the results. > It's probably possible to get those optimizations into play in other > situations, too, with a moderate amount of compiler work. > > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur -- Cheers, Artyom Shalkhakov From adamc at csail.mit.edu Thu Apr 14 09:59:55 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Thu, 14 Apr 2016 09:59:55 -0400 Subject: [Ur] C type for Ur/Web list type In-Reply-To: References: <570F78C0.4010500@csail.mit.edu> <570F7DE1.9070905@csail.mit.edu> Message-ID: <570FA25B.2070209@csail.mit.edu> If you rewrite [uri_encode] so that it doesn't use the accumulator [acc] anymore, but rather does the natural concatenations with recursive calls, then you should see very efficient imperative code come out of the Ur/Web compiler, when the result of [uri_encode] is dropped directly into page output. On 04/14/2016 07:35 AM, Artyom Shalkhakov wrote: > The code is as follows: >> fun >> uri_encode (s:string):string = let >> fun >> tohexstr i = let >> val low = i % 16 >> val high = i / 16 >> fun hexdigit i = >> case i of >> 0 => "0" | 1 => "1" | 2 => "2" | 3 => "3" | 4 => "4" | 5 => "5" | 6 => "6" | 7 => "7" | 8 => "8" | 9 => "9" >> | 10 => "A" | 11 => "B" | 12 => "C" | 13 => "D" | 14 => "E" | 15 => "F" >> | _ => error tohexstr: invalid digit {[i]} >> in >> hexdigit high ^ hexdigit low >> end >> >> fun >> aux i n s acc = >> if i < n then let >> val c = strsub s i >> in >> (* NOTE: strcat seems to be QUITE inefficient here *) >> if isalnum c || Option.isSome (String.index ";,/?:@&=+$#" c) then >> aux (i+1) n s (strcat acc (str1 c)) >> else >> aux (i+1) n s (strcat acc (strcat "%" (tohexstr (ord c)))) >> end >> else acc >> val res = aux 0 (strlen s) s "" >> in >> res >> end From adamc at csail.mit.edu Fri Apr 15 18:35:46 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Fri, 15 Apr 2016 18:35:46 -0400 Subject: [Ur] Thoughts on tags in Ur/Web? Message-ID: <57116CC2.9010607@csail.mit.edu> Someone recently requested a nice way to include a tag in Ur/Web. It doesn't seem safe to expose in its most general form, with type [string] for each attribute, since it seems like browsers could interpret those strings in quite arbitrary ways, which goes against Ur/Web's philosophy about implicit interpretation of strings as programs. Are there any opinions, then, on the right way to expose this tag? My first thought is to add an application-level whitelist of which names are allowed, just as with HTTP header names. Then the 'content' attribute could be exposed as [string], while the 'name' attribute would have an abstract type of allowable names. The programmer would need to be careful not to whitelist names that can lead to mayhem. From foldr at tutanota.com Fri Apr 15 20:24:05 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Sat, 16 Apr 2016 01:24:05 +0100 (BST) Subject: [Ur] Thoughts on tags in Ur/Web? In-Reply-To: <57116CC2.9010607@csail.mit.edu> References: <57116CC2.9010607@csail.mit.edu> Message-ID: The most obvious choice is whitelisting, at least for for http-equiv, because the specification is relatively complex. https://www.w3.org/TR/html401/struct/global.html#edef-META Whitelisting for name attribute might be less usable, but I do not know whether it is important to add keywords for search engines these days. Probably not. https://www.w3.org/TR/html401/appendix/notes.html#recs Personally I am interested to see support for the use cases below. ??? ??? ??? At the moment I just define meta as val meta : unit -> tag [Nam = string, Content = string, Http_equiv = string, Charset = string] head [] [] [] 16. Apr 2016 10:35 by adamc at csail.mit.edu: > Someone recently requested a nice way to include a content="..."> tag in Ur/Web. It doesn't seem safe to expose in its > most general form, with type [string] for each attribute, since it seems > like browsers could interpret those strings in quite arbitrary ways, which > goes against Ur/Web's philosophy about implicit interpretation of strings > as programs. > > Are there any opinions, then, on the right way to expose this tag? > > My first thought is to add an application-level whitelist of which > names are allowed, just as with HTTP header names. Then the 'content' > attribute could be exposed as [string], while the 'name' attribute would > have an abstract type of allowable names. The programmer would need to be > careful not to whitelist names that can lead to mayhem. > > _______________________________________________ > Ur mailing list > Ur at impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Sat Apr 16 08:13:50 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Sat, 16 Apr 2016 08:13:50 -0400 Subject: [Ur] Thoughts on tags in Ur/Web? In-Reply-To: References: <57116CC2.9010607@csail.mit.edu> Message-ID: <57122C7E.7080908@csail.mit.edu> I was thinking of just leaving 'http-equiv' out of the attribute list! Is there a reason to prefer over setting that header in the HTTP response? The character set is already set to UTF-8 in the HTTP response, so I think the first below is not important. The viewport example is the one I'm already aware of. It's a bit lame that the same can't be done with CSS or an HTTP response header! On 04/15/2016 08:24 PM, foldr at tutanota.com wrote: > The most obvious choice is whitelisting, at least for for http-equiv, > because the specification is relatively complex. > https://www.w3.org/TR/html401/struct/global.html#edef-META > > Whitelisting for name attribute might be less usable, but I do not > know whether it is important to add keywords for search engines these > days. Probably not. > https://www.w3.org/TR/html401/appendix/notes.html#recs > > Personally I am interested to see support for the use cases below. > > > > > At the moment I just define meta as > val meta : unit -> tag [Nam = string, Content = string, Http_equiv = > string, Charset = string] head [] [] [] > > > 16. Apr 2016 10:35 by adamc at csail.mit.edu : > > Someone recently requested a nice way to include a name="viewport" content="..."> tag in Ur/Web. It doesn't seem safe > to expose in its most general form, with type [string] for > each attribute, since it seems like browsers could interpret those > strings in quite arbitrary ways, which goes against Ur/Web's > philosophy about implicit interpretation of strings as programs. > > Are there any opinions, then, on the right way to expose this tag? > > My first thought is to add an application-level whitelist of which > names are allowed, just as with HTTP header names. Then the > 'content' attribute could be exposed as [string], while the 'name' > attribute would have an abstract type of allowable names. The > programmer would need to be careful not to whitelist names that > can lead to mayhem. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From foldr at tutanota.com Sat Apr 16 08:49:54 2016 From: foldr at tutanota.com (foldr at tutanota.com) Date: Sat, 16 Apr 2016 13:49:54 +0100 (BST) Subject: [Ur] Thoughts on tags in Ur/Web? In-Reply-To: <57122C7E.7080908@csail.mit.edu> References: <57116CC2.9010607@csail.mit.edu> <> <57122C7E.7080908@csail.mit.edu> Message-ID: Yes, actually I had the same thoughts. Also, the case of http-equiv="X-UA-Compatible" is not important, so it is 100% fine to get rid of http-equiv completely. 17. Apr 2016 00:13 by adamc at csail.mit.edu: > > I was thinking of just leaving 'http-equiv' out of the > attribute list!? Is there a reason to prefer http-equiv="X-UA-Compatible"> over setting that header in the HTTP > response? > > The character set is already set to UTF-8 in the HTTP response, so > I think the first below is not important. > > The viewport example is the one I'm already aware of.? It's a bit > lame that the same can't be done with CSS or an HTTP response header! > > On 04/15/2016 08:24 PM, > foldr at tutanota.com> wrote: > > >> The most obvious choice is whitelisting, at least for for >> http-equiv, because the specification is relatively complex. >> >> https://www.w3.org/TR/html401/struct/global.html#edef-META >> >> Whitelisting for name attribute might be less usable, but I do not >> know whether it is important to add keywords for search engines >> these days. Probably not. >> >> https://www.w3.org/TR/html401/appendix/notes.html#recs >> >> Personally I am interested to see support for the use cases below. >> ??? >> ??? >> ??? >> >> At the moment I just define meta as >> val meta : unit -> tag [Nam = string, Content = string, >> Http_equiv = string, Charset = string] head [] [] [] >> >> >> 16. Apr 2016 10:35 by >> adamc at csail.mit.edu>> : >> >> >>> Someone recently requested a nice way to include a >> name="viewport" content="..."> tag in Ur/Web. It doesn't seem safe >>> to expose in its most general form, with type [string] for >>> each attribute, since it seems like browsers could interpret >>> those strings in quite arbitrary ways, which goes against Ur/Web's >>> philosophy about implicit interpretation of strings as programs. >>> >>> Are there any opinions, then, on the right way to expose this >>> tag? >>> >>> My first thought is to add an application-level whitelist of >>> which names are allowed, just as with HTTP header names. >>> Then the 'content' attribute could be exposed as [string], while >>> the 'name' attribute would have an abstract type of allowable >>> names. The programmer would need to be careful not to whitelist >>> names that can lead to mayhem. >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicocerwick at yahoo.de Fri Apr 29 09:58:44 2016 From: nicocerwick at yahoo.de (Nico Cerwick) Date: Fri, 29 Apr 2016 13:58:44 +0000 (UTC) Subject: [Ur] local css References: <1061571316.7388803.1461938324204.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1061571316.7388803.1461938324204.JavaMail.yahoo@mail.yahoo.com> Hi everyone, i got an issue to link to my local css file. The compilation was successful but it doesn't use the given style in the frontend. It only works with a link to a webserver where i copied my css file but this isn't the right solution in the sense of Ur/Web!? Can someone help me and give me some general instructions for this? With best regards, Nico Cerwick -------------- next part -------------- An HTML attachment was scrubbed... URL: From adamc at csail.mit.edu Fri Apr 29 10:30:50 2016 From: adamc at csail.mit.edu (Adam Chlipala) Date: Fri, 29 Apr 2016 10:30:50 -0400 Subject: [Ur] local css In-Reply-To: <1061571316.7388803.1461938324204.JavaMail.yahoo@mail.yahoo.com> References: <1061571316.7388803.1461938324204.JavaMail.yahoo.ref@mail.yahoo.com> <1061571316.7388803.1461938324204.JavaMail.yahoo@mail.yahoo.com> Message-ID: <5723701A.1010707@csail.mit.edu> I recommend using the "file" directive in a .urp file. See page 6 of the manual . On 04/29/2016 09:58 AM, Nico Cerwick wrote: > Hi everyone, > > i got an issue to link to my local css file. The compilation was > successful but it doesn't use the given style in the frontend. It only > works with a link to a webserver where i copied my css file but this > isn't the right solution in the sense of Ur/Web!? > > Can someone help me and give me some general instructions for this? > > > With best regards, > > Nico Cerwick -------------- next part -------------- An HTML attachment was scrubbed... URL: