Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Lehre / SS 2011 / Programmierung und Modellierung / SML Sitzung 23.Mai.2011


Inhaltsbereich

SML Sitzung 23.Mai.2011

Plain Text icon vorl230511.txt — Plain Text, 5 KB (5320 bytes)

Dateiinhalt

mhofmann@trento:~/pum$ sml
Standard ML of New Jersey v110.69 [built: Mon Jun  8 14:15:08 2009]
- fun reverse [] = [] 
= | reverse (k::r) = reverse r @ [k];
val reverse = fn : 'a list -> 'a list
- fun mktestlist n = if n = 0 then [0] else n :: mktestlist (n-1);
val mktestlist = fn : int -> int list
- fun mktestlist2 n = if n = 0 then [0] else mktestlist2 (n-1) @ [n];
val mktestlist2 = fn : int -> int list
- mktestlist2 10000;
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- 5 :: nil;
val it = [5] : int list
- mktestlist 10;
val it = [10,9,8,7,6,5,4,3,2,1,0] : int list
- mktestlist 10000;
val it = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- reverse (mktestlist 10);
val it = [0,1,2,3,4,5,6,7,8,9,10] : int list
- reverse (mktestlist 10000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- mktestlist 10000;
val it = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- mktestlist2 10;
val it = [0,1,2,3,4,5,6,7,8,9,10] : int list
- mktestlist2 10000;
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- mktestlist 10000;
val it = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- mktestlist2 10000;
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- fun rev_aux([], acc) = acc
= | rev_aux(x::l, acc) = rev_aux(l,x::acc);
val rev_aux = fn : 'a list * 'a list -> 'a list
- rev_aux([1,2,3,4,5],acc);
stdIn:74.21-74.24 Error: unbound variable or constructor: acc
- rev_aux([1,2,3,4,5],[]);
val it = [5,4,3,2,1] : int list
- rev_aux([1,2,3],[100,200]);
val it = [3,2,1,100,200] : int list
- rev_aux(mktestlist(10000),[]);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- rev_aux(mktestlist(100000),[]);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- fun test([],acc) = acc
= | test(x::l,acc) = test(l,acc@[x]);
val test = fn : 'a list * 'a list -> 'a list
- test([1,2,3],[]);
val it = [1,2,3] : int list
- test(mktestlist(10000),[]);
val it = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- fun insertel(x,[]) = [x]
= |insertel(x,k::r) = if x <= k then x::k::r else k :: insertel(x,r);
val insertel = fn : int * int list -> int list
- insertel(5,[2,7,8,9,10]);
val it = [2,5,7,8,9,10] : int list
- insertel(5,[2,7,1,4]);
val it = [2,5,7,1,4] : int list
- fun inssort([]) = []
= |   inssort(k::r) = insertel(k,inssort(r));
val inssort = fn : int list -> int list
- inssort([1,2,3,100,4,5,7,12,3,19,6]);
val it = [1,2,3,3,4,5,6,7,12,19,100] : int list
- inssort(mktestlist(10000));
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- inssort(mktestlist(10000));
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- val liste = reverse(mktestlist(10000));
val liste = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- inssort(liste);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- let val x = 1; val y = 2; fun f(z)=z+1; val a = "mh" in f(x+y) end;
val it = 4 : int
- x;
stdIn:95.1 Error: unbound variable or constructor: x
- y;
stdIn:1.1 Error: unbound variable or constructor: y
- f;
stdIn:1.1 Error: unbound variable or constructor: f
- a;
stdIn:1.1 Error: unbound variable or constructor: a
- fun split [] = ([],[])
= | split[a] = ([a],[])
= | split(a::b::l) = let val (l1,l2) = split(l) in 
= (a::l1,b::l2) end;
val split = fn : 'a list -> 'a list * 'a list
- split([1,3,5,2,5,7,8]);
val it = ([1,5,5,8],[3,2,7]) : int list * int list
- split(mktestlist(10000));
val it =
  ([10000,9998,9996,9994,9992,9990,9988,9986,9984,9982,9980,9978,...],
   [9999,9997,9995,9993,9991,9989,9987,9985,9983,9981,9979,9977,...])
  : int list * int list
- fun merge (l,[]) = l
= | merge([],l) = l
= | merge(a::l,b::k) = if a<=b then a::merge(l,b::k) 
= else b::merge(a::l,k);
val merge = fn : int list * int list -> int list
- merge([1,3,4,6], [2,5,5,10,19,89]);
val it = [1,2,3,4,5,5,6,10,19,89] : int list
- fun mergesort [] = []
= |mergesort [a] = [a]
= |mergesort l = let val (l1,l2)= split(l) in
= merge(mergesort l1,mergesort l2) end;
val mergesort = fn : int list -> int list
- mergesort [4,3,1,6,7,2,89,199];
val it = [1,2,3,4,6,7,89,199] : int list
- val liste = mktestlist 10000;
val liste = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- inssort liste;
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- mergesort liste;
  C-c C-c
Interrupt
- mergesort [1,2,3,4,5,6,7,8,9,10,12,13];
val it = [1,2,3,4,5,6,7,8,9,10,12,13] : int list
- mergesort (mktestlist 1000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- mergesort (mktestlist 10000);
  C-c C-c
Interrupt
- mergesort (mktestlist 2000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- inssort (mktestlist 2000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- inssort (mktestlist 4000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- inssort (mktestlist 5000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- mergesort (mktestlist 5000);
val it = [0,1,2,3,4,5,6,7,8,9,10,11,...] : int list
- merge(liste,liste);
val it = [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,...]
  : int list
- split([1,2,3,4,5,6,7,8,9,10]);
val it = ([1,3,5,7,9],[2,4,6,8,10]) : int list * int list
- split([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]);
val it = ([1,3,5,7,9,11,13,15,17],[2,4,6,8,10,12,14,16,18])
  : int list * int list

Artikelaktionen


Funktionsleiste