Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Data.Functor.NormalizedConstrained.hs
{-# LANGUAGE RankNTypes, InstanceSigs, KindSignatures, GADTs, ConstraintKinds #-}
-- Paper: http://neilsculthorpe.com/publications/constrained-monad-problem.pdf
-- Talk: https://vimeo.com/69261960
import GHC.Exts
data NF :: (* -> Constraint) -> (* -> *) -> * -> * where
FMap :: c x => (x -> a) -> t x -> NF c t a
instance Functor (NF c t) where
fmap :: (a -> b) -> NF c t a -> NF c t b
fmap g (FMap h tx) = FMap (g . h) tx
liftNF :: c a => t a -> NF c t a
liftNF ta = FMap id ta
lowerNF :: (forall x. c x => (x -> a) -> t x -> t a) -> NF c t a -> t a
lowerNF fmp (FMap g tx) = fmp g tx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.