{-# language DataKinds              #-}
{-# language FlexibleInstances      #-}
{-# language FunctionalDependencies #-}
{-# language GADTs                  #-}
{-# language PolyKinds              #-}
{-# language RankNTypes             #-}
{-# language TypeOperators          #-}
module Mu.Named where

import           GHC.TypeLits

-- | A value tagged with a type-level name.
data Named n h where
  Named :: forall n h. h -> Named n h

infixr 4 :|:
-- | Heterogeneous list in which each element
--   is tagged with a type-level name.
data NamedList (hs :: [(Symbol, *)]) where
  N0    :: NamedList '[]
  (:|:) :: Named n h -> NamedList hs
        -> NamedList ('(n, h) ': hs)

-- | Used to turn tuples into 'NamedList's.
class ToNamedList p nl | p -> nl where
  toNamedList :: p -> NamedList nl

instance ToNamedList (NamedList nl) nl where
  toNamedList :: NamedList nl -> NamedList nl
toNamedList = NamedList nl -> NamedList nl
forall a. a -> a
id
instance ToNamedList () '[] where
  toNamedList :: () -> NamedList '[]
toNamedList ()
_ = NamedList '[]
N0
instance ToNamedList (Named n h) '[ '(n, h) ] where
  toNamedList :: Named n h -> NamedList '[ '(n, h)]
toNamedList Named n h
n = Named n h
n Named n h -> NamedList '[] -> NamedList '[ '(n, h)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2)
                     '[ '(n1, h1), '(n2, h2) ] where
  toNamedList :: (Named n1 h1, Named n2 h2) -> NamedList '[ '(n1, h1), '(n2, h2)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2) = Named n1 h1
n1 Named n1 h1
-> NamedList '[ '(n2, h2)] -> NamedList '[ '(n1, h1), '(n2, h2)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2 -> NamedList '[] -> NamedList '[ '(n2, h2)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3)
-> NamedList '[ '(n1, h1), '(n2, h2), '(n3, h3)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3) = Named n1 h1
n1 Named n1 h1
-> NamedList '[ '(n2, h2), '(n3, h3)]
-> NamedList '[ '(n1, h1), '(n2, h2), '(n3, h3)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList '[ '(n3, h3)] -> NamedList '[ '(n2, h2), '(n3, h3)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3 -> NamedList '[] -> NamedList '[ '(n3, h3)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4)
-> NamedList '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4) = Named n1 h1
n1 Named n1 h1
-> NamedList '[ '(n2, h2), '(n3, h3), '(n4, h4)]
-> NamedList '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList '[ '(n3, h3), '(n4, h4)]
-> NamedList '[ '(n2, h2), '(n3, h3), '(n4, h4)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList '[ '(n4, h4)] -> NamedList '[ '(n3, h3), '(n4, h4)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4 -> NamedList '[] -> NamedList '[ '(n4, h4)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5)
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4, Named n5 h5
n5) = Named n1 h1
n1 Named n1 h1
-> NamedList '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5)]
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList '[ '(n3, h3), '(n4, h4), '(n5, h5)]
-> NamedList '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList '[ '(n4, h4), '(n5, h5)]
-> NamedList '[ '(n3, h3), '(n4, h4), '(n5, h5)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4
-> NamedList '[ '(n5, h5)] -> NamedList '[ '(n4, h4), '(n5, h5)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n5 h5
n5 Named n5 h5 -> NamedList '[] -> NamedList '[ '(n5, h5)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5, Named n6 h6)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5,
 Named n6 h6)
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4, Named n5 h5
n5, Named n6 h6
n6) = Named n1 h1
n1 Named n1 h1
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6)]
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6)]
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList '[ '(n4, h4), '(n5, h5), '(n6, h6)]
-> NamedList '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4
-> NamedList '[ '(n5, h5), '(n6, h6)]
-> NamedList '[ '(n4, h4), '(n5, h5), '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n5 h5
n5 Named n5 h5
-> NamedList '[ '(n6, h6)] -> NamedList '[ '(n5, h5), '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n6 h6
n6 Named n6 h6 -> NamedList '[] -> NamedList '[ '(n6, h6)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5, Named n6 h6, Named n7 h7)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5,
 Named n6 h6, Named n7 h7)
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4, Named n5 h5
n5, Named n6 h6
n6, Named n7 h7
n7) = Named n1 h1
n1 Named n1 h1
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7)]
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7)]
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7)]
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4
-> NamedList '[ '(n5, h5), '(n6, h6), '(n7, h7)]
-> NamedList '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n5 h5
n5 Named n5 h5
-> NamedList '[ '(n6, h6), '(n7, h7)]
-> NamedList '[ '(n5, h5), '(n6, h6), '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n6 h6
n6 Named n6 h6
-> NamedList '[ '(n7, h7)] -> NamedList '[ '(n6, h6), '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n7 h7
n7 Named n7 h7 -> NamedList '[] -> NamedList '[ '(n7, h7)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5, Named n6 h6, Named n7 h7, Named n8 h8)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5,
 Named n6 h6, Named n7 h7, Named n8 h8)
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7), '(n8, h8)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4, Named n5 h5
n5, Named n6 h6
n6, Named n7 h7
n7, Named n8 h8
n8) = Named n1 h1
n1 Named n1 h1
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7), '(n8, h8)]
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7),
        '(n8, h8)]
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList
     '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8)]
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7),
        '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4
-> NamedList '[ '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8)]
-> NamedList
     '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n5 h5
n5 Named n5 h5
-> NamedList '[ '(n6, h6), '(n7, h7), '(n8, h8)]
-> NamedList '[ '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n6 h6
n6 Named n6 h6
-> NamedList '[ '(n7, h7), '(n8, h8)]
-> NamedList '[ '(n6, h6), '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n7 h7
n7 Named n7 h7
-> NamedList '[ '(n8, h8)] -> NamedList '[ '(n7, h7), '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n8 h8
n8 Named n8 h8 -> NamedList '[] -> NamedList '[ '(n8, h8)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0
instance ToNamedList (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5, Named n6 h6, Named n7 h7, Named n8 h8, Named n9 h9)
                     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9) ] where
  toNamedList :: (Named n1 h1, Named n2 h2, Named n3 h3, Named n4 h4, Named n5 h5,
 Named n6 h6, Named n7 h7, Named n8 h8, Named n9 h9)
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
toNamedList (Named n1 h1
n1, Named n2 h2
n2, Named n3 h3
n3, Named n4 h4
n4, Named n5 h5
n5, Named n6 h6
n6, Named n7 h7
n7, Named n8 h8
n8, Named n9 h9
n9) = Named n1 h1
n1 Named n1 h1
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7), '(n8, h8), '(n9, h9)]
-> NamedList
     '[ '(n1, h1), '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5),
        '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n2 h2
n2 Named n2 h2
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7),
        '(n8, h8), '(n9, h9)]
-> NamedList
     '[ '(n2, h2), '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6),
        '(n7, h7), '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n3 h3
n3 Named n3 h3
-> NamedList
     '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8),
        '(n9, h9)]
-> NamedList
     '[ '(n3, h3), '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7),
        '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n4 h4
n4 Named n4 h4
-> NamedList
     '[ '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
-> NamedList
     '[ '(n4, h4), '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8),
        '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n5 h5
n5 Named n5 h5
-> NamedList '[ '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
-> NamedList
     '[ '(n5, h5), '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n6 h6
n6 Named n6 h6
-> NamedList '[ '(n7, h7), '(n8, h8), '(n9, h9)]
-> NamedList '[ '(n6, h6), '(n7, h7), '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n7 h7
n7 Named n7 h7
-> NamedList '[ '(n8, h8), '(n9, h9)]
-> NamedList '[ '(n7, h7), '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n8 h8
n8 Named n8 h8
-> NamedList '[ '(n9, h9)] -> NamedList '[ '(n8, h8), '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: Named n9 h9
n9 Named n9 h9 -> NamedList '[] -> NamedList '[ '(n9, h9)]
forall (n :: Symbol) h (hs :: [(Symbol, *)]).
Named n h -> NamedList hs -> NamedList ('(n, h) : hs)
:|: NamedList '[]
N0