[m-dev.] Adding default clauses to the language.

Peter Schachte schachte at cs.mu.OZ.AU
Thu Aug 9 21:48:11 AEST 2001


On Thu, Aug 09, 2001 at 09:15:09PM +1000, Fergus Henderson wrote:
> On 09-Aug-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> > Could some approximation be useful with, say, some mechanism
> > for throwing exceptions for cases that aren't covered,
> > regardless of mode?
> > 
> > E.g.
> > 
> > :- func (func(T1, T2, T3) = T, list(T1), list(T2), list(T3)) = list(T)
> >     is promised_det.
> >        ^^^^^^^^^^^^
> > 
> > det_map3(_, [],       [],       []      ) = [].
> > det_map3(F, [X | Xs], [Y | Ys], [Z | Zs]) = 
> > 	[F(X, Y, Z) | det_map3(F, Xs, Ys, Zs)].
> 
> I don't like that particular syntax, because it puts an implementation
> detail in the `:- func' declaration which specifies the interface.
> 
> But if you make that a separate declaration, e.g.
> 
> :- func detmap3(func(T1, T2, T3) = T, list(T1), list(T2), list(T3)) = list(T).
> :- never_fails detmap3(in, in, in) = out.

I think it's probably going to be necessary in practice to explicitly
specify the exception to throw instead of failing.

Quibble:  I don't think "never_fails" is a good name for it.  It sounds like
it says this predicate called in this mode can't fail.  But the mode
declaration already says that (or is this in place of the mode
declaration?).  Anyway, what it really says is "in this mode, modify my code
so that if it would fail, instead raise an exception."  Maybe "never_fail"
or "ensure_no_failure" or "error_on_failure" would be better a name?

> then I think it would be a good idea.  I think I've suggested something
> along these lines previously.  This is actually more powerful than
> if-then-else, since it works in multi-moded procedures.

That's exactly what I was hoping for from "otherwise."

We seem to be dancing around the edges of mode-specific code.  In this case
we want to bend failure into an exception.  At other times we want to force
(nondet,multi) code to be (semidet,det).  Is there some generalization we
could apply to cover these things (and maybe more) with one language feature?

-- 
Peter Schachte                     Brook's Law: Adding manpower to a late
mailto:schachte at cs.mu.OZ.AU        software project makes it later 
http://www.cs.mu.oz.au/~schachte/  
Phone: +61 3 8344 9166             
PGP key available, see web page    
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list