<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Raphael,<br><br>  I have made the necessary changes and the code look like this. Now i have a new error:<br><br>this is the code:<br><br>************************************************************************************<br>:- module oplossing1.<br><br>:- interface.<br>:- import_module io.<br><br>:- pred main(io.state::di, io.state::uo) is det.<br><br>:- implementation.<br>:- import_module int, list,string,map.<br><br>:- func tabel(list(T)) = list({T,int}).<br>        tabel([]) = [].<br>        tabel([X]) =  tabel_aux([X], []).<br><br><br>:- func inc_freq(T, list({T,int})) = list({T,int}).<br>        inc_freq(I, []) = [{I,1}].<br>    inc_freq(I, [{J,N}|Freqs]) =   (if (I =
 J)<br>                                          then [{J,N+1}|Freqs]   % I's counter incremented, rest untouched<br>                          else Freqs ++ [{J,N}]       % keep J in the list, but increment the<br>                       ).               % frequency of I in Freqs<br>                      <br><br>:- func tabel_aux(list(T), list({T,int})) =
 list({T,int}).<br>        tabel_aux([], FreqList) = FreqList.<br>        tabel_aux([X|Xs], FreqList) =  inc_freq(X,FreqList)  ++<br>                        tabel_aux(Xs,FreqList).<br><br><br>:- func compare_freq({T,int}, {T,int}) = comparison_result.<br>    compare_freq({_, N1}, {_, N2}) = Result :-<br>    compare(Result, N1, N2).<br><br>main(!IO):-<br>%io.print(tabel(string.to_char_list("this is a test")),!IO),<br>io.nl(!IO),<br>io.print(tabel([3,2,1,2,1,1,2]),!IO),<br>io.nl(!IO).<br><br>*********************************************************************************************<br><br><span style="font-weight: bold;">the error is, i think am missing something somewhere :</span><br><br>oplossing1.m:011: In `tabel(in) =
 out':<br>oplossing1.m:011:   error: determinism declaration not satisfied.<br>oplossing1.m:011:   Declared `det', inferred `semidet'.<br>oplossing1.m:013:   In argument 1 of clause head:<br>oplossing1.m:013:   in argument 2 of functor `[|]/2':<br>oplossing1.m:013:   unification with `list.[]' can fail.<br><br><br>Thanks for your reply. Hope you will help me fix it.<br><br>Regards,<br>Eddie<br><br><br><br><br><br><br><br><br><br>--- On <b>Fri, 12/17/10, Raphael Collet <i><rco@missioncriticalit.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Raphael Collet <rco@missioncriticalit.com><br>Subject: Re: [mercury-users] A Bug:  Converting List To List Of Tuples<br>To: mercury-users@csse.unimelb.edu.au<br>Cc: "win1for@yahoo.com" <win1for@yahoo.com><br>Date: Friday, December 17, 2010, 10:52 AM<br><br><div
 class="plainMail">On 12/17/2010 03:57 PM, <a ymailto="mailto:win1for@yahoo.com" href="/mc/compose?to=win1for@yahoo.com">win1for@yahoo.com</a> wrote:<br>> Hi Raphael,<br>><br>> I have pieced all the pieces together except the sorting part. I get<br>> some errors.This is the code:<br>><br>><br>> - module oplossing1.<br>><br>> :- interface.<br>> :- import_module io.<br>><br>> :- pred main(io.state::di, io.state::uo) is det.<br>><br>> :- implementation.<br>> :- import_module int, list,string,map.<br>><br>> :- func tabel(list(T)) = list({T,int}).<br>> tabel([X]) = tabel_aux([X], []).<br>><br>><br>> :- func inc_freq(T, list({T,int})) = list({T,int}).<br>> inc_freq(I, []) = [{I,1}].<br>> inc_freq(I, [{J,N}|Freqs]) = (if (I = J)<br>> then [{J,N+1}|Freqs] % I's counter incremented, rest untouched<br>> else Freqs ++ [{J,N}] % keep J in the list, but increment the<br>> ). % frequency of
 I in Freqs<br>><br>><br>> :- func tabel_aux(list(T), list({T,int})) = list({T,int}).<br>> tabel_aux([], FreqList) = FreqList.<br><br>This second clause is not valid:<br><br>> tabel_aux([X|Xs], FreqList) = (inc_freq(X,FreqList) ,<br>> tabel_aux(Xs,FreqList)).<br><br>inc_freq(X,FreqList) returns a value, which is a 'new' FreqList.  What <br>do you do with that value?<br><br>><br>><br>> main(!IO):-<br>> %io.print(tabel(string.to_char_list("this is a test")),!IO),<br>> io.nl(!IO),<br>> io.print(tabel([3,2,1,2,1,1,2]),!IO),<br>> io.nl(!IO).<br>><br><br>Otherwise the rest looks ok.<br><br>Cheers,<br>Raphael<br></div></blockquote></td></tr></table><br>