Skip to content

Instantly share code, notes, and snippets.

@masaeedu
Created September 24, 2019 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masaeedu/a2e58e1aa350d139ea97a03fbb3fdbda to your computer and use it in GitHub Desktop.
Save masaeedu/a2e58e1aa350d139ea97a03fbb3fdbda to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds, GADTs, RankNTypes, TypeOperators #-}
module Traversals where
import Control.Monad.Free
type (~>) f g = forall x. f x -> g x
data Nat = Z | S Nat
data HVec n f a
where
HNil :: a -> HVec Z f a
HCons :: f (HVec n f a) -> HVec (S n) f a
data HFunList a b t x
where
HFunList :: HVec n a x -> (HVec n b x -> t x) -> HFunList a b t x
type HTraversal s t a b = s ~> HFunList a b t
test :: (Functor a, Functor b) => HTraversal (Free a) (Free b) a b
test (Pure a) = HFunList (HNil a) (\(HNil b) -> Pure b)
test (Free ar) = HFunList (HCons (_ <$> ar)) (\(HCons br) -> Free (_ <$> br))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment