[mercury-users] How efficient is mercury?

Erwan Jahier Erwan.Jahier at imag.fr
Tue Apr 20 17:07:46 AEST 2004

On Mon, 19 Apr 2004, David Overton wrote:

> After being a Mercury developer for several years I've recently started
> a new job where I'm programming in Ocaml. I can't comment on the
> efficiency difference between them because I haven't done any
> comparisons.  I'll give a few comments on my experience moving to OCaml.
> The main thing I've noticed is that programming in OCaml feels a lot
> less "safe" that programming in Mercury.  Even sticking to the purely
> functional subset of OCaml (which I've mainly done so far), the OCaml
> compiler catches many fewer errors than the Mercury compiler.  E.g. the
> OCaml compiler does not give warnings for singleton variables, which
> often indicate a typo (if anyone knows how to turn this on, please let
> me know!).  Also, OCaml will not tell you whether a pattern match is
> exhaustive, like the Mercury determinism analysis is able to do for
> switches.

I don't agree. As long as you do not use " | _ -> " at the end of your
pattern match, the compiler does check the exhautivity.

        Objective Caml version 3.06

# type foo = | Titi | Toto ;;
# let f x = match x with Titi -> 1;;
Warning: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
val f : foo -> int = <fun>

> This makes it much harder to update all affected places if
> you add an alternative to a discriminated union type.
> I've gained a new appreciation for the Mercury type checker.  It seems
> (qualitatively) to be much better at reporting type errors at the point
> at which the error occurs, rather than giving a confusing message that
> points to something several lines later.

I you <<force>> the type (in the Mercury spirit), my experience is that
compiler points the rigth place 99% of the time.

You can do it like that:

	let (f : int -> float -> 'a -> res) =
	fun i f a ->

Except from those 2 points, i pretty much agree with what you are saying;
i never feel really safe with ocaml... and i have been bitten in places
where i am sure that Mercury wouldn't.

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list