I could add an "assert" function to lib/ur/top.ur

---

fun assert [a] (cond: bool) (msg: string) (loc: string) (x:a): a =

  if cond then x else error <xml>{[msg]} at {[loc]}</xml>

---

Usage:

---

fun safeDivBy [a] (_:eq a) (_:num a) (loc:string) (denom: a) (n: a): a =

  assert (denom <> zero) "precond: illegal divisor" loc <|

    n `divide` denom


fun main (): transaction page =

  let return <xml><body>{[result]}</body></xml>
  where
    val result = safeDivBy _LOC_ 0 5
  end

----------------

BTW, "let ... where ... end" is not documented in the reference manual.


_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to