[mercury-users] Typeclass constraint on HO (function) discriminator

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Thu Apr 20 12:12:48 AEST 2006


Dear all,

I'm running into type errors when I attempt to
constrain a higher-order function discriminator
of a type.  It may be due to an existential issue,
(it complains that I need a function of arity X,
but I am passing it a(n existentially quantified)
function of arity X (with a typeclass constraint 
on an argument), so I'm quite stuck, as my 
attempts to create an existential function lead 
to (many) more errors.  How do I get the 
following program to compile and to run?

The refman shows straightforward examples of
calling existential functions, but not HO ones.
Must HO functions be universal?  If so, is there
a workaround to impose a typeclass constraint on
an argument in an HO function?

Thanks for your help!

Sincerely,
Doug Auclair

----- program -----

:- module proba.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module int.

:- typeclass generator(X) where [
      func generate(int, X) = int
].

:- type foo
        ---> some [Gen]
             { int, func(int, Gen) = int } => generator(Gen).

:- type bar ---> bar.

:- instance generator(bar) where [generate(Int, _) = Int + 3].

main -->
	print("Hello world!\n"),
	foo_me_baby({ 5,
	              (func(X, Gen) = Baz :- Baz = generate(X, Gen)) },
	            bar).

:- pred foo_me_baby(foo::in, Gen::in, io::di, io::uo) is det.
foo_me_baby({ X, Func }, Gen) -->
	print(Func(X, Gen)).


--------------------------------------------------------------------------
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