[m-dev.] generic result types

Paul Bone pbone at csse.unimelb.edu.au
Wed Feb 18 13:53:58 AEDT 2009

On Wed, Feb 18, 2009 at 01:36:44PM +1100, Peter Ross wrote:
> Hi,
> Do people think it would be useful to add the following generic types
> to the standard library?
> :- type result(T, E)
>     --->    ok(T)
>     ;       error(E)
>     .
> :- type partial_result(T, E) == partial_result(T, T, E).
> :- type partial_result(T, P, E)
>     --->    ok(T)
>     ;       error(P, E)
> :- type result(E)
>     --->    ok
>     ;       error(E)
>     .
> Then the various io and stream types could be redefined in terms of these types.
> I ask because we have written a lot of code at MC which should use these generic
> result types, so I was going to add this to our library but ian
> suggested we should
> see first if it goes better in the mercury standard library.

I would find them useful.  In programs I write in Mercury that aren't
part of Mercury itself I'm often defining types that look like this.

I'd also find it useful to have a result that can carry warnings:

:- type result_with_warnings(T, M)
    --->    ok(T, cord(M))
    ;       error(cord(M)).

In the case of error one of the messages is 'critical' or 'fatal'.  M is
for message since errors and warnings are both types of messages.

Often when writing code like this I'd find it handy to have some
predicates that can abstract away some details of flow-control like
Monads do in Haskell.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/developers/attachments/20090218/f1318d7f/attachment.sig>

More information about the developers mailing list