Skip to content

Instantly share code, notes, and snippets.

View jobjo's full-sized avatar

Joel Bjornson jobjo

  • London
View GitHub Profile
@jobjo
jobjo / Higher-Kinded F#
Last active August 29, 2015 14:11
What if F# supported higher-kinded polymorphism?
// Functor interface.
type Functor<'F> = { map : ('T -> 'U) -> 'F<'T> -> 'F<'U> }
// Monad interface.
type Monad<'M> = {
return : 'T -> 'M<'T>
join : 'M<'M<'T>> -> 'M<'T>
}
// Monad "library" (operations over monads).
(* General functor signature. *)
module type FUNCTOR = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
(* General def of catamorphism module, parameterized by a functor *)
module Cata (F : FUNCTOR) = struct
type 'a t = 'a F.t
(* Functors and modular implicits
* opam switch 4.02.0+modular-implicits
* eval `opam config env`
*)
module type FUNCTOR = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
let map {F : FUNCTOR} = F.map