[m-dev.] question about polymorphic higher order terms

Ian MacLarty maclarty at csse.unimelb.edu.au
Sun May 24 01:06:41 AEST 2009


Hi,

Suppose I have a higher order function that converts a value of type T
to a string.  It's type is func(T) = string.  Now suppose I want to
pass this function to a predicate and apply it to values of different
types.  Something like:

:- pred p((func(T) = string)::in, io::di, io::uo) is det.

p(F, !IO) :-
    io.write_string(F(1), !IO),
    io.write_string(F("one"), !IO).

won't work, because the caller binds T, so F is monomorphic.

So my question: Is there a way to pass a polymorphic higher order term
to a predicate so that it is still polymorphic inside that predicate?
I realise that one could define a typeclass with the function as a
method, but that would require the function to have an extra dummy
argument.  Does anyone know of a more elegant solution, or could
someone point me to any previous discussions or literature on the
topic?

Cheers,
Ian.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list