[mercury-users] Syntactic sugar for higher order types and modes
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Jul 20 20:56:19 AEST 2000
On 17-Jul-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> 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.
I like the idea, but not the particular syntax that you've chosen for it.
The reasons that I don't like the particular syntax that you've chosen
for it are
- Assuming you do the same thing for predicates as for functions,
it overloads the syntax `:- pred foo is bar.':
this can mean either that (1) `foo' is a predicate with zero arguments
and with determinism `bar', or that (2) `foo' is a predicate
whose type is given by the type name `bar'.
You could get the compiler to resolve the ambiguity by
assuming that if `bar' is one of the names of the standard
determinism categories (`det', `semidet', `multi', `nondet',
`cc_multi', `cc_nondet', `erroneous', or `failure'), then it
is (1) and otherwise it is (2), but IMHO it would be nicer
to choose a syntax which did not have that ambiguity.
- Similarly, it overloads the syntax `:- mode foo is bar'.
- In `:- pred foo is bar.', case (2), the use of the word `is'
does not match the meaning of `is' in the English language,
so it doesn't read well. Really what this declaration is
saying is that `foo' is a predicate with type `bar', not
that `foo' _is_ `bar'.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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