Skip to content

Instantly share code, notes, and snippets.

@Octachron
Last active November 6, 2017 23:15
Show Gist options
  • Save Octachron/3b28513420b5f771d96c60c1f348a674 to your computer and use it in GitHub Desktop.
Save Octachron/3b28513420b5f771d96c60c1f348a674 to your computer and use it in GitHub Desktop.
module type app = sig
type 'a t
val pure : 'a -> 'a t
val ( <$> ) : ('a -> 'b) t -> 'a t -> 'b t
end
module Unzip(App:app) = struct
open App
let rec f = function
| [] -> pure []
| a :: q -> pure List.cons <$> a <$> f q
end
module Pair =
struct
type 'a t = 'a * 'a
let pure x = x, x
let (<$>) (f,g) (x,y) = (f x,g y)
end
module U = Unzip(Pair)
let l1, l2 = U.f [1,2;3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment