[Ur] Questions regarding "nesting" of `xml ctx inp []` and `transaction (xml ctx inp [])`

Sergey Mironov grrwlf at gmail.com
Thu Jul 23 03:45:04 EDT 2015


> Informally, this would meet that "transactional-ness" ("transactionality"?)
> must "bubble up" from (inner) subterms to the (outer) containing term. If
> you want to have a transactional term anywhere inside a larger term, then
> that larger term must itself also be transactional.
>

Sounds right for me. Think about [transactional something] as about
solid thing. You can't access its internals any more. The only way to
deal with it is to 'execute' it by calling from inside other function
which also should be transactional. We also have a primitive
combinator 'return' which turns pure value into 'transactional'. All
the nesting is performed on 'pure' values only: <xml>a {b} c</xml> is
much like strings  "a " + b + " c", where b can't be transactional.

fun nest1 (x : xbody) : xbody =
  <xml>1 {x} 1</xml> (* CORRECT: all values are pure; we don't need
return here *)

 fun nest2 (x: xbody) : transactional xbody =
  return <xml>1 {x} 1</xml>  (* CORRECT: note 'return' that turns pure
<xml>1 {x} 1</xml> into transactional form. fun nest2 x = return
(nest1 x) would also be correct *)

fun nest3 (tx: transaction xbody) : xbody =
  x <- tx ;  (* ERROR: do-notation is applicable only for
transactional functions, nest1 is not transactional since it return
non-transactional value. "Operator"  ";" accepts transaction (tx) on
its left side, a function (fn x => <xml>...</xml>) of type xbody ->
transaction xbody from its right side and returns transaction xbody.
Unfortunately, nest3 is declared to return pure xbody so we have type
error here. *)
  <xml>1 {x} 1</xml>


Regards,
Sergey


PS You have to read the some Monad tutorial. Haskell and other
languages have similar concepts. I think, 'Real world Haskell' book
contains well-commented explanations. 'transaction monad' is called
'IO monad' there



More information about the Ur mailing list