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

Ralph Becket rbeck at microsoft.com
Thu Aug 9 21:41:36 AEST 2001


> From: Fergus Henderson [mailto:fjh at cs.mu.OZ.AU]
> Sent: 09 August 2001 12:15
> 
> On 09-Aug-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> > Ah well, it would have been nice had it been workable :)
> >
> > :- 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.

I shouldn't have used a function - I was using a variant of the

:- func f(T1) = T2 is semidet.

shorthand.  `promised_det' could go on the mode declaration of a 
predicate, too, e.g.

:- pred int_to_char(int, char).
:- mode int_to_char(in, out) is promised_det.

int_to_char(0, '\x00').
...
int_to_char(97, a).
int_to_char(98, b).
...
int_to_char(255, '\xFF').

However, one could add

:- mode int_to_char(out, in) is det.

indicating to the reader that use of the promised_det mode places a
proof burden on the client code.

- Ralph
--------------------------------------------------------------------------
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