Advertisement
juaniisuar

UF ML

Sep 9th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. fun create [] = []
  2. | create (x::y) = (x,x)::(create y);
  3.  
  4. exception nopepuntoexe;
  5.  
  6. fun findAux x [] z = raise nopepuntoexe
  7. | findAux x ((a,b)::c) z =
  8. if x = a andalso a = b
  9. then
  10. b
  11. else
  12. if x = a
  13. then
  14. findAux b z z
  15. else
  16. findAux x c z
  17.  
  18. fun find x a = findAux x a a;
  19.  
  20. fun unionAux x y [] rest k = raise nopepuntoexe
  21. | unionAux x y ((a,b)::c) rest k = if k = a
  22. then
  23. rest@((a,x)::c)
  24. else
  25. unionAux x y c (rest@[(a,b)]) k;
  26.  
  27. fun union x y a = unionAux x y a [] (find y a);
  28.  
  29.  
  30. val l = create([1,2,3,4,5,6]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement