[mercury-users] higher-order programming
Peter Ross
pro at missioncriticalit.com
Tue May 24 16:14:13 AEST 2005
On Tue, May 24, 2005 at 10:54:03AM +1000, Peter Schachte wrote:
> Hi Peter,
>
> > My solution was to instead map the higher order functions to data
> > constructors, which allows one to easily combine the combinators,
> > however it's not possible to add new base combinators easily to the
> > system, which is an annoying drawback to the system.
>
> Could you use a type class to solve that problem? Then each
> constructor would be its own type, which I expect would make
> maintenance easier.
>
Thanks Peter, I think you may have found the work-around that
isn't so clunky.
:- typeclass cfilter(T) where [
filter(T, content) = list(content)
].
:- type keep ---> keep.
:- instance cfilter(none) where [
filter(keep, C) = [C]
].
:- type tag ---> tag(string).
:- instance cfilter(tag) where [
filter(tag(T), celem(E)) = ( E ^ name = T -> [celem(E)] ; [] ),
filter(tag(T), ctext(_)) = []
].
:- type o(T, U) ---> o(T, U).
:- instance cfilter(o(T, U)) <= (cfilter(T), cfilter(U)) where [
filter(o(F, G), C) = condense(map(filter(F), filter(G, C))),
].
Then the simple call would be
Contents = filter(tag("child") `o` keep, C)
however one would easily be able to extend the base combinators.
--------------------------------------------------------------------------
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