The Haskell function doesn't actually match on the two parameters. It only matches on the first parameter and takes the second parameter as is.
In F#, you can match on the first argument, and return a function that processes the second argument:
let rec mux = function
| [] -> (function ys -> ys)
| x::xt -> (function ys -> x :: mux ys xt)
But I find it clearer (and I think it's more efficient — at least it is in OCaml) to take in all the arguments at once, then analyze the argument you need to discriminate on:
let rec mux xs ys =
match xs with
| [] -> ys
| x::xt -> x :: mux ys xt
If you wanted to match on both variables, there would be several solutions. You could nest function
constructs:
let rec mux = function
| [] -> (function [] -> … | y::yt -> …)
| x::xt -> (function [] -> … | y::yt -> …)
But here again I prefer nesting match
constructs:
let rec mux xs ys =
match xs with
| [] -> (match ys with
| [] -> …
| y::yt -> …)
| x::xt -> (match ys with
| [] -> …
| y::yt -> …)
Alternatively, it's often nicer to match on the pair of inputs; it depends how coupled the two inputs are.
let rec mux xs ys =
match xs, ys with
| [], [] -> …
| [], y::yt -> …
| x::xt, [] -> …
| x::xt, y::yt -> …