2 years ago

#58259

test-img

nicolas

higher order fix point in OCaml

What are all the possible implementations the following second-order example in OCaml ? Here is some very simple Haskell code exhibiting a fold, aka the universal property of the initial algebra FixH.

I imagine it's easy to make it with OCaml functors. What are the other options ?

Is there any known implementation with "lightweight higher order kind" style ?

{-# LANGUAGE RankNTypes #-}

newtype FixH t a = FixH {unFixH :: t (FixH t) a}

type Tnat f g = forall a. f a -> g a

class FunctorH t where
  hmap :: Tnat f g -> Tnat (t f) (t g)

foldFixH :: forall t f. FunctorH t => Tnat (t f) f -> Tnat (FixH t) f
foldFixH alg = alg . hmap (foldFixH alg) . unFixH

haskell

ocaml

higher-kinded-types

fixpoint-combinators

0 Answers

Your Answer

Accepted video resources