[mercury-users] exceptions considered bloody annoying

Ralph Becket rafe at cs.mu.OZ.AU
Tue Apr 16 15:36:44 AEST 2002

Richard A. O'Keefe, Tuesday, 16 April 2002:
> Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> 	* For example, in Okasaki's "Purely Functional Data Structures", he
> 	  suggests using using an exception to signal when an already-present
> 	  member of a set data structure is being inserted.  If the exception is
> 	  caught, the insert operation reduces to the identity function and no
> 	  extra memory is allocated.  Otherwise the insert operation proceeds as
> 	  per usual.
> This has always seemed to me like a silly approach.
> It's far better to define one's interfaces so that they make sense
> as often as possible.  The operation
>     union_element_set :: a -> Set a -> Set a
> should have the semantics
>     abs(union_element_set x s) = abs(s) U {abs(x)}
> where abs is the abstraction function.  I'm in the process of crunching
> some real data now, and life (already difficult), would be a LOT harder
> if I had to insert my own checks to program around unmathematical restrictions
> that only make interfaces pointlessly complicated, and error-prone to use.

Okasaki was referring to the implementation of the set insertion
operation, not its interface.  This use of exceptions is purely for
efficiency and entirely invisible to the caller.

- Ralph
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list