[mercury-users] type (class?) parameters

Michael Day mcda at students.cs.mu.oz.au
Fri Oct 13 23:53:29 AEDT 2000


Something that has been bugging me is how the following use of templates
in C++ would translate into Mercury or any other language with equivalent
type system:

template <typename T, int size>
struct
{
	T buffer[size];

	void do_something()
	{
		for (int i = 0; i < size; ++i)
		{
			buffer[i] = foo(buffer[i]);
		}
	}
};

Kind of like a type constructor that takes values as well as types? Eh?
It's useful sometimes in C++ for making functions that will take the dot
product of vectors and cleanly catch mismatched lengths. Can anyone offer
any guidance on what this would look like in Mercury?

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