Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1.  
  2. type car = string*string*int
  3.  
  4. let car1 = ("Opel", "astra", 1999)
  5. let car2 = ("Renault", "megane", 2004)
  6. let car3 = ("Opel", "corsa", 2009)
  7. let car4 = ("Nissan", "micra", 2004)
  8. let car5 = ("Opel", "corsa", 2009)
  9. let car6 = ("Nissan", "micra", 2004)
  10.  
  11. let carList = [car1;car2;car3;car4;car5;car6]
  12.  
  13. let apperiance cars productionYear =
  14. let rec countApperiance filteredCars result =
  15. match filteredCars with
  16. | [] -> result
  17. | (cars1,cars2,cars3)::t ->
  18. let rec countAndRemove currentCars resultCars (x1,x2,x3) count =
  19. match currentCars with
  20. | [] -> (resultCars, count)
  21. | (h1,h2,h3)::t -> if(h1=x1 && h2=x2) then countAndRemove t resultCars (x1,x2,x3) (count+1)
  22. else countAndRemove t ((h1,h2,h3)::resultCars) (x1,x2,x3) count
  23. in let (l1,a1) = countAndRemove filteredCars [] (cars1,cars2,cars3) 0
  24. in countApperiance l1 ((cars1,(cars2,a1))::result)
  25.  
  26. in countApperiance (List.filter (function (x,y,z)->z==productionYear) cars) [];;
  27.  
  28. apperiance carList 2004;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement