Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. (4,a)(1,b)(2,c)(2,a)(1,d)(4,e) --> ((4 a) b (2 c) (2 a) d (4 e))
  2.  
  3. let rec transform l =
  4. match l with
  5. | (x,y)::t -> if x = 1 then y::transform(t) else [x; y]::transform(t)
  6. | [] -> []
  7.  
  8. Error: This expression has type int list
  9. but an expression was expected of type int
  10.  
  11. if x = 1
  12. then y :: transform (t)
  13. else [x; y] :: transform t
  14.  
  15. type 'a element =
  16. | Single of 'a
  17. | Count of int * 'a
  18.  
  19. let rec transform = function
  20. | [] -> []
  21. | (x,y)::t ->
  22. if x = 1 then Single y::transform t
  23. else Count (x, y)::transform t
  24.  
  25. let compact (x, y) =
  26. if x = 1 then Single y else Count (x, y)
  27.  
  28. let transform list = List.map compact list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement