[mercury-users] inst decls and fixed-length lists
Ralph Becket
rafe at cs.mu.OZ.AU
Thu Feb 23 14:29:32 AEDT 2006
Hi Doug,
[is there any way you could stick to 78 columns? Your e-mail gets badly
mangled by line wrapping.]
doug.auclair at logicaltypes.com, Wednesday, 22 February 2006:
> :- inst two_bits(T, End) == bound([T|bound([T|bound(End)])]).
> :- inst four_gone(T, End) == two_bits(T, two_bits(T, End)).
> :- inst pieces_of_eight(T) == four_gone(T, four_gone(T, [])).
>
> ... and with exactly two elements, the two_bits inst was well-behaved:
>
> TwoPly = [red, green],
> print_twosies(TwoPly)
>
> :- pred print_twosies(list(T)::in(two_bits(T, []), io::di, io::uo) is det.
> print_twosies(Colours) --> print(Colours), nl.
>
> but trying to use the composed insts gets me compiler errors:
>
> Fore = [purple, crimson, cyan, amber],
> print_foursome(Fore)
>
> :- pred print_foursome(list(T)::in(four_gone(T, []), io::di, io::uo) is det.
> print_foursome(TrueColours) --> print(TrueColours), nl.
Hmm. Well, one problem is that you're using T as a type variable
and as an inst variable here. Inst polymorphism is something that is
not well tested and is known to be buggy. You should be able to fix
things like this:
:- pred print_foursome(list(T)::in(four_gone(ground, []), io::di, io::uo)
is det.
print_foursome(TrueColours) --> print(TrueColours), nl.
-- Ralph
--------------------------------------------------------------------------
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