Re: [Ur] Browser-based adventure game
> fun render (sgs : source gameState) : signal xbody = Thanks! I changed the function as you suggested. -Michael ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
Re: [Ur] Browser-based adventure game
Hi Saulo, Here are some points of doubt: - What is the type of a function that produces arbitrary HTML snippets. Is xbody correct? - What is the name of "show" and "eq" functions? I used "show_list", "show_gameState", "show_pair", and "eq_pair" instead of just "show" and "eq". Is this correct? - Is there a more convenient syntax for list construction than "1 :: 2 :: 3 :: []", something like "[1, 2, 3]"? - I had to pass both a "gameState" and a "source gameState" parameter to the "render" function (for the same game state). Is there a way around that? - I minimized the use of mutable data. So when the game state changes much of the page gets updated. This should probably be done in a more fine-grained way in reality. - Does Ur/Web do tail-call optimization? - Will there be other collections beyond lists (dictionary/map, array)? Best, Michael > On 12 Oct 2016, at 16:27, Saulo Araujo <sau...@gmail.com> wrote: > > Hi Michael, > > Thanks for sharing your game with the community. I skimmed its source code > and I did not found anything that I would qualify as a non-canonical use of > Ur/Web. However, beware that I am an Ur/Web beginner too :) Maybe you can > pinpoint which parts of the code you are afraid are non-canonical uses of the > language... > > Sincerely, > Saulo > > On Wed, Oct 12, 2016 at 8:33 AM, Michael Rohs > <michael.r...@hci.uni-hannover.de> wrote: > Hi, > > As part of my exploration of Ur/Web I wrote a tiny browser-based adventure > game. > > https://github.com/mirohs/urweb-adventure > > It might be helpful to others looking at the language. If you find > non-canonical use of the language (I guess there is some...), please let me > know. > > Cheers, > Michael > > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
[Ur] Browser-based adventure game
Hi, As part of my exploration of Ur/Web I wrote a tiny browser-based adventure game. https://github.com/mirohs/urweb-adventure It might be helpful to others looking at the language. If you find non-canonical use of the language (I guess there is some...), please let me know. Cheers, Michael ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
Re: [Ur] int to string?
Oh, I see. Thanks! -Michael > On 09 Oct 2016, at 13:38, Saulo Araujo <sau...@gmail.com> wrote: > > Hi Michael, > > I believe that happens because the module List binds a function to the show > variable: > > val show = fn [a] (_ : show a) => > let > fun show' (ls : list a) = > case ls of > [] => "[]" > | x :: ls => show x ^ " :: " ^ show' ls > in > mkShow show' > end > > Therefore, opening the List module shadows the show function defined in the > Basis module. > > val show : t ::: Type -> show t -> t -> string > > Regards, > Saulo > > > > On Sun, Oct 9, 2016 at 6:55 AM, Michael Rohs > <michael.r...@hci.uni-hannover.de> wrote: > Hi Saulo, > > Thanks for your help. Thanks for the suggestion to add type annotations. It > indeed works, but only if I don't open the List module. > > The problem appears if I add module List (even without using any of its > functions). > > test.urp: > $/list > test > > test.ur: > open List > > if I remove "open List" from test.ur it works. > > I don't understand why... > > Here is the full test.ur: > -- > (*open List*) <-- error if uncommenting this line > > fun int2string (i : int) : string = show i > val s = int2string 123 > > fun main () = > let > val stuff = "apple" :: "key" :: "goat" :: [] > fun predicate (s : string) : bool = s <> "apple" > (* val stuff2 = List.filter predicate stuff*) > in > return > {[s]} > > > end > -- > > Best, > Michael > > > > On 09 Oct 2016, at 10:04, Saulo Araujo <sau...@gmail.com> wrote: > > > > Hi Michael, > > > > Your definition of int2string is fine. For example, the code > > > > fun int2string (i : int) : string = show i > > > > val s = int2string 10 > > > > compiles without errors. I suspect the problem is in another part of your > > code. The error message suggests that you have an expression that produces > > a list where something else is expected. In my experience learning > > languages of the ML family, in situations like this, it helps to > > type-annotate arguments and results of functions. Eventually, it also helps > > to type-annotate expressions. For example > > > > val h = 10 > > val t = [] > > val s = (h :: t) : int > > > > Thanks to the type annotation ": int", the compiler will produce an error > > saying that there is a list int where an int is required: > > > > Expression: Basis.Cons [int] {1 = h, 2 = t} > > Have con: list int > > Need con: int > > Incompatible constructors > > Have: list int > > Need: int > > > > Regards, > > Saulo > > > > On Sun, Oct 9, 2016 at 4:07 AM, Michael Rohs > > <michael.r...@hci.uni-hannover.de> wrote: > > Hi all, > > > > I have a question to a very simple problem. How to convert an integer to a > > string? > > > > This does not work: > > > > fun int2string (i : int) : string = show i > > > > Error message: > > > > /.../test.ur:19:36: (to 19:40) Unification failure > > Expression: show [] _ > > Have con: show (list ) > > Need con: -> > > Incompatible constructors > > Have: show (list ) > > Need: -> > > > > I couldn't find anything else like Int.toString or so. > > > > Thank you very much in advance! > > > > Best, > > Michael > > > > > > ___ > > Ur mailing list > > Ur@impredicative.com > > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > > > > ___ > > Ur mailing list > > Ur@impredicative.com > > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
Re: [Ur] int to string?
Hi Saulo, Thanks for your help. Thanks for the suggestion to add type annotations. It indeed works, but only if I don't open the List module. The problem appears if I add module List (even without using any of its functions). test.urp: $/list test test.ur: open List if I remove "open List" from test.ur it works. I don't understand why... Here is the full test.ur: -- (*open List*) <-- error if uncommenting this line fun int2string (i : int) : string = show i val s = int2string 123 fun main () = let val stuff = "apple" :: "key" :: "goat" :: [] fun predicate (s : string) : bool = s <> "apple" (* val stuff2 = List.filter predicate stuff*) in return {[s]} end -- Best, Michael > On 09 Oct 2016, at 10:04, Saulo Araujo <sau...@gmail.com> wrote: > > Hi Michael, > > Your definition of int2string is fine. For example, the code > > fun int2string (i : int) : string = show i > > val s = int2string 10 > > compiles without errors. I suspect the problem is in another part of your > code. The error message suggests that you have an expression that produces a > list where something else is expected. In my experience learning languages of > the ML family, in situations like this, it helps to type-annotate arguments > and results of functions. Eventually, it also helps to type-annotate > expressions. For example > > val h = 10 > val t = [] > val s = (h :: t) : int > > Thanks to the type annotation ": int", the compiler will produce an error > saying that there is a list int where an int is required: > > Expression: Basis.Cons [int] {1 = h, 2 = t} > Have con: list int > Need con: int > Incompatible constructors > Have: list int > Need: int > > Regards, > Saulo > > On Sun, Oct 9, 2016 at 4:07 AM, Michael Rohs > <michael.r...@hci.uni-hannover.de> wrote: > Hi all, > > I have a question to a very simple problem. How to convert an integer to a > string? > > This does not work: > > fun int2string (i : int) : string = show i > > Error message: > > /.../test.ur:19:36: (to 19:40) Unification failure > Expression: show [] _ > Have con: show (list ) > Need con: -> > Incompatible constructors > Have: show (list ) > Need: -> > > I couldn't find anything else like Int.toString or so. > > Thank you very much in advance! > > Best, > Michael > > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur > > ___ > Ur mailing list > Ur@impredicative.com > http://www.impredicative.com/cgi-bin/mailman/listinfo/ur ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
[Ur] int to string?
Hi all, I have a question to a very simple problem. How to convert an integer to a string? This does not work: fun int2string (i : int) : string = show i Error message: /.../test.ur:19:36: (to 19:40) Unification failure Expression: show [] _ Have con: show (list ) Need con: -> Incompatible constructors Have: show (list ) Need: -> I couldn't find anything else like Int.toString or so. Thank you very much in advance! Best, Michael ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
[Ur] ListEdit Demo
Hi, listEdit is one of the demos. Looking through it I was surprised that these lines in the add function head' <- get head; case head' of Nil => set head cons | _ => return () are necessary. I changed them to return () and it still works, as I expected, so the relevant part becomes in set tail cons; set tailP tail'; return () end Is this correct or am I missing something? Best, Michael ___ Ur mailing list Ur@impredicative.com http://www.impredicative.com/cgi-bin/mailman/listinfo/ur