[m-dev.] question about polymorphic higher order terms
Julien Fischer
juliensf at csse.unimelb.edu.au
Sun May 24 03:32:28 AEST 2009
On Sun, 24 May 2009, Ian MacLarty wrote:
> 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?
What you want here is called rank-2 polymorphism, which Mercury doesn't
(currently) support. Search for literature on rank-2, rank-N, or
higher-ranked polymoprhism or types -- there's a vast amount of it.
Haskell (ghc at least) supports this.
Julien.
--------------------------------------------------------------------------
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