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

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 9 21:15:09 AEST 2001


On 09-Aug-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> Ah well, it would have been nice had it been workable :)
> 
> 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.

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.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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