Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 531

Interleaving in OCaml

$
0
0

I am trying to create a function which interleaves a pair of triples such as ((6, 3, 2), ( 4, 5 ,1)) and create a 6-tuple out of this interleaving.I made some research but could understand how interleaving is supposed to work so I tried something on my own end ended up with a code that is creating a 6-tuple but not in the right interleaved way. This is my code

let interleave ((a, b, c), (a', b', c')) =  let sort2 (a, b) = if a > b then (a, b) else (b, a) in  let sort3 (a, b, c) =     let (a, b) = sort2 (a, b) in    let (b, c) = sort2 (b, c) in    let (a, b) = sort2 (a, b) in    (a, b, c) in  let touch ((x), (y)) =     let (x) = sort3 (x) in    let (y) = sort3 (y) in    ((x),(y)) in  let ((a, b, c), (a', b', c')) =     touch ((a, b, c), (a', b', c')) in  (a, b', a', b, c, c');;

Can someone please explain to me how with what functions I can achieve a proper form of interleaving. I haven't learned about recursions and lists in case you would ask why I am trying to do it this way.Thank you already.


Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>