[mercury-users] What does logic buy us over pure functional programming?

Ralph Becket rbeck at microsoft.com
Mon Apr 30 23:26:59 AEST 2001


Well, all these languages are Turing complete so from that perspective
they are all equally powerful.  Expressive power usually refers to the
ease ("naturalness") with which you can express solutions.  Mercury
gives you pretty much everything you get in your standard functional
programming language (modulo some extra parentheses and non-Full Monty
currying), but also supports a great chunk of logic programming in the
tried and tested style (here trading the convenience of Prolog's
aliasable logical variables for speed and safety.)

> I have been mulling over what a logic language really adds to one's
> programming arsenal. I mean, if you think about it, it seems that it
> basically adds two things:
> 
> [...]

I enjoy having the following in particular:
- semidet predicates rather than functions returning bool;
- predicates returning multiple values rather than functions returning
  tuples;
- generating multiple procedures from the same predicate can make for
  very concise code, e.g.

	:- pred list(T) `contains_sublist` list(T).
	:- mode in `contains_sublist` in is semidet.

	Xs `contains_sublist` Zs :-
		append(_, Ys, Xs),	% append(out, out, in) is multi
		append(Zs, _, Ys).	% append(in, out, in) is
semidet.

- the ability to write concise constraints, e.g.

	:- pred all_even(list(T)).
	:- mode all_even(in) is semidet.

	all_even(Xs) :- all [X] ( member(X, Xs) => X `mod` 2 = 0 ).

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