Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created February 20, 2021 20:11
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 oisdk/52c73636adfa09cd577cc8b05fbe82e1 to your computer and use it in GitHub Desktop.
Save oisdk/52c73636adfa09cd577cc8b05fbe82e1 to your computer and use it in GitHub Desktop.
{-# LANGUAGE GADTs, DataKinds, TypeOperators, FlexibleInstances, KindSignatures, RankNTypes, QuantifiedConstraints, FlexibleContexts #-}
data Free (fs :: [(* -> *) -> * -> *]) (a :: *) where
Pure :: a -> Free '[] a
Effect :: f (Free fs) a -> Free (f ': fs) a
instance Functor (Free '[]) where
fmap f (Pure x) = Pure (f x)
instance ((forall x. Functor x => Functor (f x))
,Functor (Free fs))
=> Functor (Free (f ': fs)) where
fmap f (Effect xs) = Effect (fmap f xs)
instance Applicative (Free '[]) where
pure = Pure
Pure f <*> Pure x = Pure (f x)
instance ((forall x. Functor x => Functor (f x))
,(forall x. Applicative x => Applicative (f x))
,Applicative (Free fs))
=> Applicative (Free (f ': fs)) where
pure x = Effect (pure x)
Effect fs <*> Effect xs = Effect (fs <*> xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment