[Ur] I know this must be malformed Ur

Artyom Shalkhakov artyom.shalkhakov at gmail.com
Thu Mar 9 00:52:54 EST 2017


Hello Isaac,

2017-03-09 5:32 GMT+06:00 Isaac Torbett <izacht13 at gmail.com>:
> table topic: { Id: int, Title: string, Body: string, Links: string, Author:
> string, Summary: string }
>   PRIMARY KEY Id
>

First, you should break it up:

> fun main () =
>     returnBlob (
>         textBlob (
>             Json.toJson {
>                 Topics = queryL1 (SELECT topic.Title, topic.Body FROM topic)
>             }
>         )
>     ) (blessMime "application/json")
>

into:

> fun main () =
>     topics <- queryL1 (SELECT topic.Title, topic.Body FROM topic);
>     returnBlob (
>         textBlob (
>             Json.toJson {Topics = topics}
>         )
>     ) (blessMime "application/json")

Briefly, query1 returns [transaction (list ...)], and the only way to
"extract" the list out of it is via the "bind" operation (using the
syntax sugar above, with the "VARIABLE <- EXPRESSION"). Various
Haskell monad tutorials will go to any desirable depth on this.

You will need to provide an instance of [class json] for the record
[{Topics : list topic}] (what's the type of an element of topic? I
used [topic]). There's a function for that:

> val json_record : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json $ts

I guess you will have no problem with this one.

> I've tried changing line 12 to:
>
> , blessMime "application/json")
>
> As that seems to me like it makes more sense, but my one line of error turns
> into quite a lot more than one line. (*Measure in lines because I am still
> having trouble reading the errors.*)
>
> Error for the first code block is:
> "/home/izach/projects/urweb/test.ur:7:3: (to 7:14) Can't resolve type class
> instance"
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>



-- 
Cheers,
Artyom Shalkhakov



More information about the Ur mailing list