Last active
July 8, 2018 15:56
-
-
Save Profpatsch/da32febab011fde0a99c3a2fe34e9c45 to your computer and use it in GitHub Desktop.
Going from a type implementing Generic1 to a Holey (which can be used to get a Zipper for free)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, TypeOperators, FlexibleContexts, TypeFamilies #-} | |
module FunctorCombo.Generic ( | |
encode | |
) where | |
import GHC.Generics | |
import qualified FunctorCombo.Functor as F | |
class Encode gen where | |
type DerG gen :: * -> * | |
encode :: gen a -> DerG gen a | |
instance Encode (Rec0 c) where | |
type DerG (Rec0 c) = F.Const c | |
encode (K1 c) = F.Const c | |
instance Encode Par1 where | |
type DerG Par1 = F.Id | |
encode (Par1 r) = F.Id r | |
instance Functor f => Encode (Rec1 f) where | |
type DerG (Rec1 f) = (f F.:. F.Id) | |
encode (Rec1 fp) = F.O $ fmap F.Id fp | |
instance Encode (f :+: g) where | |
type DerG (f :+: g) = (f F.:+: g) | |
encode (L1 fp) = F.InL fp | |
encode (R1 fp) = F.InR fp | |
instance Encode (f :*: g) where | |
type DerG (f :*: g) = (f F.:*: g) | |
encode (fp :*: gp) = fp F.:*: gp | |
instance Encode (f :.: g) where | |
type DerG (f :.: g) = (f F.:. g) | |
encode (Comp1 fgp) = F.O fgp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment