[Ur] Attempting to do Exercise 7.3 of Gian Perrone's UrWeb (blog) tutorial - trying to a logout() function and link to it - getting compiler errors

Stefan Scott Alexander stefanscottalexx at gmail.com
Wed Jan 28 13:47:40 EST 2015


Hello UrWeb users -

I've been learning UrWeb and and currently I'm studying Gian Perrone's
excellent UrWeb tutorial (about creating a simple blog).

The existing code (https://github.com/gian/urtutorial) has been running
fine.

Now I'm trying to do Excercise 7.3 on Step 7, here:

http://www.expdev.net/urtutorial/step7.html

I order to do this, I have been trying to:

- define a logout() function (a link which logs the user out, and sends
them to a different "You have logged out!" page)

- add this link to all the pages in the application (when the user is
authenticated)

I have been getting compiler errors, and I am unable to figure out how to
do this correctly.

In order to show my code (and the compiler error messages - which can be
rather lengthy) I have forked the tutorial on GitHub, and posted my
attempted change there, along with the compiler output:

https://github.com/DonaldScott/urtutorial/commit/78e0f6a4d0885744bf4729d674a46867bfdb4633

I'm not sure if it's complaining about the type of the new functions which
I added:

fun pageWithLogout pg =
   pg' <- pg;
   return <xml>
            {pg'}
            <p><a link={logout()}>Logout</a></p>
          </xml>

and logout () = clearCookie userSession;
  return <xml>You have logged out!</xml>

or maybe about something else ("unable to unify record types"?)

I believe the type of the two new functions being defined above should be
[transaction page].

In order to "add" the link to an arbitrary page [pg], I have been
attempting to:

- given a value [pg] of type [transaction page], "unwrap" the functional
value contained inside it, using [pg' <- pg]

- "splice" the result into an xml fragment, using [<xml> ... {pg'} ...
</xml>] while appending a link to the [logout()] function

- "wrap" the overall result in a value that is again of type [transaction
page], using [return]

Intuitively, this seems to make sense (to me :-)

However, it is generating compiler errors - which may be about the above
function - or may be about something else on the page, as it is mentioning
"unable to unify record types" for various lines in the code - some of
which are further below the new function being defined (the compiler is
complaining about lines: 38, 57, 48, 31).

Thanks for any help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150128/0a3f36db/attachment.html>


More information about the Ur mailing list