Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (4,a)(1,b)(2,c)(2,a)(1,d)(4,e) --> ((4 a) b (2 c) (2 a) d (4 e))
- let rec transform l =
- match l with
- | (x,y)::t -> if x = 1 then y::transform(t) else [x; y]::transform(t)
- | [] -> []
- Error: This expression has type int list
- but an expression was expected of type int
- if x = 1
- then y :: transform (t)
- else [x; y] :: transform t
- type 'a element =
- | Single of 'a
- | Count of int * 'a
- let rec transform = function
- | [] -> []
- | (x,y)::t ->
- if x = 1 then Single y::transform t
- else Count (x, y)::transform t
- let compact (x, y) =
- if x = 1 then Single y else Count (x, y)
- let transform list = List.map compact list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement