[mercury-users] Error detection rate in Mercury vs Other Languages (esp C++ and Python)

Julien Fischer juliensf at csse.unimelb.edu.au
Sat Dec 3 17:47:50 AEDT 2011




On Sat, 3 Dec 2011, Peter Ross wrote:

> One thing I would highly recommend though is to make semidet code
> which depends on the cases of a type use a deterministic switch
> followed by your semidet failure code.
>
> :- type t
>  ---> f
>  ;     g.
>
> require_det (
>  ( X = f,
>    Succeed = yes
>  ; X = g,
>    Succeed = no
>  )
> ),
> Succeed = yes.
>
> The reason I do this is that if at a later date you add a new
> alternative type to t, you want the compiler to point out to you need
> to handle the new alternative.

Or you can just require the switch to be complete, e.g

    require_complete_switch [X] (
       X = f,
       ...
    ;
       X = g,
       ...
    )

which will have the same effect but without requiring the code to be
rearranged just to get the completeness check on the switch.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list