(* util.rml *)
module Util:
  relation bound	: ((''a * 'b) list, ''a) => 'b option
  relation lookup	: ((''a * 'b) list, ''a) => 'b
  relation intersect	: (''a list, ''a list) => ''a list
end

relation bound =
  axiom bound([], _) => NONE

  rule	x = x'
	----------------
	bound((x,y)::_, x') => SOME y

  rule	not x = x' & bound(env, x') => result
	----------------
	bound((x,_)::env, x') => result
end

relation lookup =
  rule	bound(env, x) => SOME y
	----------------
	lookup(env, x) => y
end

relation intersect' =
  axiom	intersect'([], _, zs) => zs

  rule	list_member(x, ys) => true & intersect'(xs, ys, x::zs) => zs'
	----------------
	intersect'(x::xs, ys, zs) => zs'

  rule	list_member(x, ys) => false & intersect'(xs, ys, zs) => zs'
	----------------
	intersect'(x::xs, ys, zs) => zs'
end

relation intersect =
  rule	intersect'(xs, ys, []) => zs
	----------------
	intersect(xs, ys) => zs
end
