Assigment 2 ML Source Code
(*i is the ISBN for the book and j is the string for the person*)
datatype Lib=
New |
conPeople of Lib*int*string|
con of Lib*int;
datatype WaitList= NewWL |
wait of WaitList*int*string;
val x="";
val numExe=0;
fun off(NewWL)=NewWL
| off(wait(NewWL,i,j))=NewWL
| off(wait(S,i,j))=wait(off(S),i,j);
fun add(New,i)=con(New,i)
| add(S,i)=con(S,i);
fun cko(New,i,j)=New
| cko(conPeople(S,ii,jj),i,j)=if (ii=i) then cko(S,i,j)
else conPeople(cko(S,i,j),ii,jj)
| cko(con(S,ii),i,j)=if (ii=i) then conPeople(cko(S,i,j),i,j)
else con(cko(S,i,j),ii);
fun cki(New,i,j)=New
| cki(con(S,ii),i,j)=if (ii=i) then cki(S,i,j)
else con(cki(S,i,j),ii)
| cki(conPeople(S,ii,jj),i,j)=if (ii=i) then con(cki(S,i,j),i)
else conPeople(cki(S,i,j),i,j);
exception noSuchBook;
fun has(New,i)= false
| has(con(S,ii),i)=if(ii=i) then true
else has(S,i)
|has(conPeople(S,ii,j),i)=if(ii=i) then true
else has(S,i);
fun here(New,i)=0
| here(con(S,ii),i)= if(ii=i) then 1+here(S,i)
else here(S,i)
| here(conPeople(S,ii,j),i)= if(ii=i) then here(S,i)
else here(S,i);
fun num(New,i)=0
| num(con(S,ii),i)= if(ii=i) then 1+num(S,i)
else num(S,i)
| num(conPeople(S,ii,j),i)= if(ii=i) then 1+num(S,i)
else num(S,i)
val a= New;
val b= add(a,1);
val c= add(b,2);
val e= cko(c,1,"df");
val z= cki(e,1,"df");
val k=num(e,1);
val l=here(e,1);
val hs=has(e,1);
datatype Lib=
New |
conPeople of Lib*int*string|
con of Lib*int;
datatype WaitList= NewWL |
wait of WaitList*int*string;
val x="";
val numExe=0;
fun off(NewWL)=NewWL
| off(wait(NewWL,i,j))=NewWL
| off(wait(S,i,j))=wait(off(S),i,j);
fun add(New,i)=con(New,i)
| add(S,i)=con(S,i);
fun cko(New,i,j)=New
| cko(conPeople(S,ii,jj),i,j)=if (ii=i) then cko(S,i,j)
else conPeople(cko(S,i,j),ii,jj)
| cko(con(S,ii),i,j)=if (ii=i) then conPeople(cko(S,i,j),i,j)
else con(cko(S,i,j),ii);
fun cki(New,i,j)=New
| cki(con(S,ii),i,j)=if (ii=i) then cki(S,i,j)
else con(cki(S,i,j),ii)
| cki(conPeople(S,ii,jj),i,j)=if (ii=i) then con(cki(S,i,j),i)
else conPeople(cki(S,i,j),i,j);
exception noSuchBook;
fun has(New,i)= false
| has(con(S,ii),i)=if(ii=i) then true
else has(S,i)
|has(conPeople(S,ii,j),i)=if(ii=i) then true
else has(S,i);
fun here(New,i)=0
| here(con(S,ii),i)= if(ii=i) then 1+here(S,i)
else here(S,i)
| here(conPeople(S,ii,j),i)= if(ii=i) then here(S,i)
else here(S,i);
fun num(New,i)=0
| num(con(S,ii),i)= if(ii=i) then 1+num(S,i)
else num(S,i)
| num(conPeople(S,ii,j),i)= if(ii=i) then 1+num(S,i)
else num(S,i)
val a= New;
val b= add(a,1);
val c= add(b,2);
val e= cko(c,1,"df");
val z= cki(e,1,"df");
val k=num(e,1);
val l=here(e,1);
val hs=has(e,1);