[mercury-users] Square types
Michael Day
mikeday at corplink.com.au
Wed Jun 13 18:45:50 AEST 2001
> For example, you can come up with a type for perfectly balanced trees:
> A type containing only an odd number of items:
> We can have a type containing only square numbers of items using the
> fact that the nth square is equal to the sum of the first n odd
> numbers:
> I admit that last one took some thought...
Goodness me, that's clever.
One more question. As I can't make an arbitrarily sized tuple an instance
of a type class in Mercury, it is convenient sometimes to define a tuple
type, basically a list but with the length encoded in the type:
:- type empty_tuple ---> empty_tuple.
:- type tuple(S, T) ---> tuple(S, T).
X = tuple(1, tuple("foo", empty_tuple))
equivalent to X = {1, "foo"}, but allowing this:
:- instance something(tuple(S, T)) <= something(T) ...
Anyway, would it be possible to make a tuple whose length is embedded in
its type and can contain only a square number of elements?
(To be honest, I'd like to use them to store square matrices of arbitrary
size and be able to know that two different tuples have the *same* size).
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