[mercury-users] dependent types with mercury

Vladimir Gubarkov xonixx at gmail.com
Fri Apr 8 00:10:06 AEST 2011


I've read this blogpost


And thought, I could try to implement smth like even- (odd-) sized list
using appropriate modes.
I tried next:

:- module lists1.

:- interface.

:- import_module io.

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

:- implementation.

:- import_module list.

%:- inst even_list ---> [] ; [ground|even_list]. % XXX
:- inst even_list ---> [] ; [ground,ground|even_list]. % YYY

%:- type even_list(T) ---> []; [T,T|even_list(T)].

%:- pred t(even_list(int)).
:- pred t(list(int)).
:- mode t(in(even_list)) is semidet.

main(!IO) :-
( t(L) ->

But this resulted in

D:\stuff\test\mercury\deptypes>mmc.bat --make lists1
Making Mercury\int3s\lists1.int3
Making Mercury\ints\lists1.int
Making Mercury\cs\lists1.c
lists1.m:014: In definition of inst `lists1.even_list'/0:
lists1.m:014:   error: undefined inst `[|]'/2.
Error: system command received signal 1.
** Error making `Mercury\cs\lists1.c'.

Note, that if I comment YYY line and uncomment XXX - code compiles well.
My will is that I could compile code with L=[1,2,3,4,5,6] (even sized list)
but not with L=[1,2,3,4,5,6,7] (odd).

Is this possible with mercury?

Sincerely yours,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20110407/2cbc1901/attachment.html>

More information about the users mailing list