
Robert Dockins
On Nov 15, 2006, at 9:48 AM, Jón Fairbairn wrote:
But instead of “blah (head [ v | (n,v) <- env, n==target ]) blah”, you could write
blah the_v_in_scope blah where (the_v_in_scope:_) = [ v | (n,v) <- env, n==target ]
Or how about.... ??
lookupVarible target env = case [ v | (n,v) <- env, n==target ] of (x:_) -> x _ -> assert False $ "BUG: Unexpected variable out of scope "++ (show target)++" in environment "++(show env)
... lookupVariable target env ....
It seems to me that every possible use of a partial function has some (possibly imagined) program invariant that prevents it from failing. Otherwise it is downright wrong. 'head', 'fromJust' and friends don't do anything to put that invariant in the program text.
Hear hear. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk