[Haskell-cafe] Re: Debugging partial functions by the rules
jon.fairbairn at cl.cam.ac.uk
Wed Nov 15 12:02:16 EST 2006
Robert Dockins <robdockins at fastmail.fm> writes:
> 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.
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe