table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
fun cache id =
res <- oneOrNoRows (SELECT tab.Val
FROM tab
WHERE tab.Id = {[id]});
return
cache
{case res of
None => ?
| Some row => {[row.Tab.Val]}}
fun sillyRecursive {Id = id : int, FooBar = fooBar} =
if fooBar <= 0
then 0
else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1}
fun cacheR (r : {Id : int, FooBar : int}) =
res <- oneOrNoRows (SELECT tab.Val
FROM tab
WHERE tab.Id = {[r.Id]});
return
cacheR {[r.FooBar]}
{case res of
None => ?
| Some row => {[row.Tab.Val]}}
(* fun cache2 id v = *)
(* res <- oneOrNoRows (SELECT tab.Val *)
(* FROM tab *)
(* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
(* return *)
(* Reading {[id]}. *)
(* {case res of *)
(* None => Nope, that's not it. *)
(* | Some _ => Hooray! You guessed it!} *)
(* *)
(* fun cache2 id1 id2 = *)
(* res1 <- oneOrNoRows (SELECT tab.Val *)
(* FROM tab *)
(* WHERE tab.Id = {[id1]}); *)
(* res2 <- oneOrNoRows (SELECT tab.Val *)
(* FROM tab *)
(* WHERE tab.Id = {[id2]}); *)
(* return *)
(* Reading {[id1]} and {[id2]}. *)
(* {case (res1, res2) of *)
(* (Some _, Some _) => Both are there. *)
(* | _ => One of them is missing.} *)
(* *)
fun flush id =
dml (UPDATE tab
SET Val = Val * (Id + 2) / Val - 3
WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
return
Changed {[id]}!
fun flash id =
dml (UPDATE tab
SET Foo = Val
WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
return
Maybe changed {[id]}?
fun floosh id =
dml (UPDATE tab
SET Id = {[id + 1]}
WHERE Id = {[id]});
return
Shifted {[id]}!
(* val flush17 = *)
(* dml (UPDATE tab *)
(* SET Val = Val * (Id + 2) / Val - 3 *)
(* WHERE Id = 17); *)
(* return *)
(* Changed specifically 17! *)
(* *)
(* fun flush id = *)
(* res <- oneOrNoRows (SELECT tab.Val *)
(* FROM tab *)
(* WHERE tab.Id = {[id]}); *)
(* (case res of *)
(* None => dml (INSERT INTO tab (Id, Val) *)
(* VALUES ({[id]}, 0)) *)
(* | Some row => dml (UPDATE tab *)
(* SET Val = {[row.Tab.Val + 1]} *)
(* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
(* return *)
(* {case res of *)
(* None => Initialized {[id]}! *)
(* | Some row => Incremented {[id]}!} *)
(* *)