[Ur] Compile error in simple test app involving 'list' and 'eq'; difficulty understanding higher-order expressions

Stefan Scott Alexander stefanscottalexx at gmail.com
Wed Dec 24 21:37:24 EST 2014


Hello -

Thank you for the clarification about how I was using 'eq' wrong.

Basically I had just been going through *all* the signatures / definitions
in list.urs and list.ur, trying out an example of each one in a web page,
for learning purposes.

But as you explained, in the case of 'eq', an expression like 'eq nums1
nums2' would not normally be used - the way to test for equality would be
by simply writing 'nums1 = nums2'.

I have corrected this simple web page (file list_test.ur) accordingly:

  open List

  val nums1 = 1 :: 2 :: 3 :: []
  val nums2 = 101 :: 102 :: 103 :: []

  val fn1 x y = (2 * x) + y
  val minus100 x = x - 100

  (* val nums1eqnums2 = (nums1 = nums2) *)

  fun main () : transaction page =
  return <xml><body>
      <li> val nums1 = 1 :: 2 :: 3 :: []</li>
      <li> val nums2 = 101 :: 102 :: 103 :: []</li>
      <li> val fn1 x y = (2 * x) + y</li>
      <li> foldl fn1 1 nums1 = {[ foldl fn1 1 nums1 ]}</li>
      <li> foldl fn1 1 nums2 = {[ foldl fn1 1 nums2 ]}</li>
      <li> mp minus100 nums2 = {[ mp minus100 nums2 ]}</li>
      <li> (nums1 = nums2) = {[ nums1 = nums2 ]}</li>
      <li> (nums1 = (mp minus100 nums2)) = {[ nums1 = (mp minus100 nums2)
]}</li>
  </body></xml>

(The line val nums1eqnums2 = (nums1 = nums2) is shown above, but commented
out. In this particular scenario, it would not be necessary, since the
expression 'nums1 = nums2' is being "spliced into" the HTML and is thus
isolated from any preceding expressions.)

The above code now compiles, and when I visit the following page in the
browser:

  http://127.0.0.1:8080/List_test/main

it correctly displays:

  - val nums1 = 1 :: 2 :: 3 :: []
  - val nums2 = 101 :: 102 :: 103 :: []
  - val fn1 x y = (2 * x) + y
  - foldl fn1 1 nums1 = 13
  - foldl fn1 1 nums2 = 613
  - mp minus100 nums2 = 1 :: 2 :: 3 :: []
  - (nums1 = nums2) = False
  - (nums1 = (mp minus100 nums2)) = True

###
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20141225/d12da1e3/attachment.html>


More information about the Ur mailing list