Created
August 23, 2017 21:09
-
-
Save MonoidMusician/65e25ba5dca348fd7f33a85ae2529c4b to your computer and use it in GitHub Desktop.
Generic.Rep.Sum to list
This file contains hidden or 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
module Main where | |
import Prelude | |
import Type.Proxy (Proxy(..)) | |
import Data.Generic.Rep | |
foreign import kind List | |
foreign import data Cons :: Type -> List -> List | |
foreign import data Nil :: List | |
class AppendList (l :: List) (r :: List) (o :: List) | l -> r o | |
instance appendCons :: AppendList l r o => AppendList (Cons a l) r (Cons a o) | |
instance appendNil :: AppendList Nil r r | |
class SumToList g (l :: List) | g -> l | |
instance sumCons :: | |
( SumToList ga la | |
, SumToList gb lb | |
, AppendList la lb l | |
) => SumToList (Sum ga gb) l | |
instance sumField :: SumToList (Constructor name arg) (Cons (Constructor name arg) Nil) | |
-------------- test | |
data LProxy (l :: List) = LProxy | |
solveSumToList :: forall s r l. Generic s r => SumToList r l => Proxy s -> LProxy l | |
solveSumToList _ = LProxy | |
data Maybe a = Nothing | Just a | |
derive instance genericList :: Generic (Maybe a) _ | |
maybeList = solveSumToList (Proxy :: Proxy (Maybe Int)) :: LProxy | |
(Cons (Constructor "Nothing" NoArguments) (Cons (Constructor "Just" (Argument Int)) Nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment