Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. let rec quicksort = function
  2. [] -> []
  3. | [x] -> [x]
  4. | xs -> let small = List.filter (fun y -> y < List.hd xs ) xs
  5. and large = List.filter (fun y -> y >= List.hd xs ) xs
  6. in quicksort small @ quicksort large;;
  7.  
  8. quicksort([8;4;6;5;6;7])
  9.  
  10. let rec quicksort' = function
  11. [] -> []
  12. | x::xs -> let small = List.filter (fun y -> y <= x ) xs
  13. and large = List.filter (fun y -> y >= x ) xs
  14. in quicksort' small @ (x :: quicksort' large);;
  15.  
  16. quicksort([6;2;1;1])
  17.  
  18. let f1 x = x 1 1;;
  19.  
  20. let f2 x y z = x ( y ^ z );;
  21.  
  22.  
  23. Let f1 x = x 1 1;;
  24. f1 jest powiedzmy typu a->b, (gdzie a to typ x)
  25. x jest typu int->int->c
  26. Ponieważ ciało f1 składa się tylko z wywołania x, ich efekt jest taki sam czyli b=c
  27. Stąd f1: (int - int - c) - c, a ocaml zamieni nasze c na oznaczenie 'a.
  28. Na polski: f1 to funkcjonał, który przyjmuje pewną funkcję int-int-c i wywołuje ją dla dwóch jedyne
  29.  
  30.  
  31.  
  32. Let f2 x y z = x (y^z);;
  33. Niech f2: a-b-c-d, natomiast x y z to kolejno a b c.
  34. b=c=string, co wiemy z operacji ^ .
  35. x: string - e
  36. d=e, bo f2 to tylko wywołanie x (jak poprzednio)
  37. Czyli f2: (string-d)-string -string - d = <fun>
  38. Gdzie d będzie nazwane przez ocaml jako 'a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement