[mercury-users] Syntactic sugar for higher order types and modes

Ralph Becket rbeck at microsoft.com
Mon Jul 17 21:43:33 AEST 2000


When writing higher order code, Mercury's syntax can be a little
burdensome.  I'd like to suggest a small extension to the syntax
of the language, borrowing from Haskell, which should make matters
a little easier on the eyes and fingers.

The idea is simply this: rather than having to write, say,

:- func foo(pred(char), list(char)) = list(char).
:- mode foo(pred(in) is semidet, in) = out is det.

:- func bar(pred(string), list(string)) = list(string).
:- mode bar(pred(in) is semidet, in) = out is det.

:- func baz(pred(int), list(int)) = list(int).
:- mode baz(pred(in) is semidet, in) = out is det.

where {foo,bar,baz}/2 each handle their particular types specially,
one might write

:- type filter_fn(T) == (func(pred(T), list(T)) = list(T)).
:- mode filter_md    :: (func(pred(in) is semidet, in) = out is det).

:- func foo is filter_fn(char).
:- mode foo is filter_md.

	% Sim. for bar and baz.

The transformation from the latter into the former is trivial, unless
I've missed something.

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