exception BadArg; (* The first argument to demux is P. P is a predicate, example fun test(x) = x = 4; The second argument to demux is a list of arguments for the predicate. The third argument to demux is a list of functions. If the predicate is true for a certain argument, the corresponding function is called. The fourth argument to demux is the argument to the functions *) fun demux (P, c::cs, f::fs, r) = if P(c) then f(r) else demux (P, cs, fs, r) | demux (P, nil, _, r) = raise BadArg | demux (P, _, nil, r) = raise BadArg ; (* demux 1 is same as demux, except the fourth argument is a list of arguments for the functions *) fun demux1 (P, c::cs, f::fs, r::rs) = if (P(c)) then f(r) else demux1 (P, cs, fs, rs) | demux1 (P, nil, _, _) = raise BadArg | demux1 (P, _, nil, _) = raise BadArg | demux1 (P, _, _, nil) = raise BadArg ;