{-# LANGUAGE AllowAmbiguousTypes,
ConstraintKinds,
CPP,
DataKinds,
FlexibleContexts,
FlexibleInstances,
GADTs,
KindSignatures,
MultiParamTypeClasses,
PatternSynonyms,
PolyKinds,
RankNTypes,
ScopedTypeVariables,
TypeApplications,
TypeFamilies,
TypeOperators,
ViewPatterns #-}
module Frames.RecF (V.rappend, V.rtraverse, rdel, CanDelete,
AllCols,
UnColumn,
StripFieldNames(..),
mapMono,
ColFun, ColumnHeaders,
columnHeaders) where
import Data.Proxy
import qualified Data.Vinyl as V
import Data.Vinyl (Rec(..))
import Data.Vinyl.Derived (StripFieldNames(..), Unlabeled)
import Data.Vinyl.Functor ((:.))
import Data.Vinyl.TypeLevel
import Frames.Col
import Frames.TypeLevel
import GHC.TypeLits (Symbol, KnownSymbol, symbolVal)
class ColumnHeaders (cs::[(Symbol,*)]) where
columnHeaders :: proxy (Rec f cs) -> [String]
instance ColumnHeaders '[] where
columnHeaders :: proxy (Rec f '[]) -> [String]
columnHeaders proxy (Rec f '[])
_ = []
instance forall cs s c. (ColumnHeaders cs, KnownSymbol s)
=> ColumnHeaders (s :-> c ': cs) where
columnHeaders :: proxy (Rec f ((s :-> c) : cs)) -> [String]
columnHeaders proxy (Rec f ((s :-> c) : cs))
_ = Proxy s -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy s
forall k (t :: k). Proxy t
Proxy::Proxy s) String -> [String] -> [String]
forall a. a -> [a] -> [a]
: Proxy (Rec Any cs) -> [String]
forall (cs :: [(Symbol, *)]) (proxy :: * -> *)
(f :: (Symbol, *) -> *).
ColumnHeaders cs =>
proxy (Rec f cs) -> [String]
columnHeaders (forall k (t :: k). Proxy t
forall (f :: (Symbol, *) -> *). Proxy (Rec f cs)
Proxy::Proxy (Rec f cs))
type family ColFun f x where
ColFun f (Rec g rs) = Rec (f :. g) rs
type family UnColumn (ts :: [(Symbol,*)]) where
UnColumn '[] = '[]
UnColumn ((s :-> t) ': ts) = t ': UnColumn ts
type AllCols c ts = AllConstrained c (UnColumn ts)
mapMonoV :: (AllAre a ts, Functor f)
=> (a -> b)
-> Rec f ts
-> Rec f (ReplaceAll b ts)
mapMonoV :: (a -> b) -> Rec f ts -> Rec f (ReplaceAll b ts)
mapMonoV a -> b
_ Rec f ts
RNil = Rec f (ReplaceAll b ts)
forall u (a :: u -> *). Rec a '[]
RNil
mapMonoV a -> b
f (f r
x :& Rec f rs
xs) = (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f f a
f r
x f b -> Rec f (ReplaceAll b rs) -> Rec f (b : ReplaceAll b rs)
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (a -> b) -> Rec f rs -> Rec f (ReplaceAll b rs)
forall a (ts :: [*]) (f :: * -> *) b.
(AllAre a ts, Functor f) =>
(a -> b) -> Rec f ts -> Rec f (ReplaceAll b ts)
mapMonoV a -> b
f Rec f rs
xs
mapMono :: (AllAre a (Unlabeled ts),
StripFieldNames ts,
StripFieldNames (ReplaceAllSnd b ts),
ReplaceAll b (Unlabeled ts) ~ Unlabeled (ReplaceAllSnd b ts))
=> (a -> b)
-> Rec V.ElField ts
-> Rec V.ElField (ReplaceAllSnd b ts)
mapMono :: (a -> b) -> Rec ElField ts -> Rec ElField (ReplaceAllSnd b ts)
mapMono a -> b
f = Rec Identity (Unlabeled (ReplaceAllSnd b ts))
-> Rec ElField (ReplaceAllSnd b ts)
forall (ts :: [(Symbol, *)]).
StripFieldNames ts =>
Rec Identity (Unlabeled ts) -> Rec ElField ts
withNames (Rec Identity (Unlabeled (ReplaceAllSnd b ts))
-> Rec ElField (ReplaceAllSnd b ts))
-> (Rec ElField ts
-> Rec Identity (Unlabeled (ReplaceAllSnd b ts)))
-> Rec ElField ts
-> Rec ElField (ReplaceAllSnd b ts)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b)
-> Rec Identity (Unlabeled ts)
-> Rec Identity (ReplaceAll b (Unlabeled ts))
forall a (ts :: [*]) (f :: * -> *) b.
(AllAre a ts, Functor f) =>
(a -> b) -> Rec f ts -> Rec f (ReplaceAll b ts)
mapMonoV a -> b
f (Rec Identity (Unlabeled ts)
-> Rec Identity (Unlabeled (ReplaceAllSnd b ts)))
-> (Rec ElField ts -> Rec Identity (Unlabeled ts))
-> Rec ElField ts
-> Rec Identity (Unlabeled (ReplaceAllSnd b ts))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rec ElField ts -> Rec Identity (Unlabeled ts)
forall (ts :: [(Symbol, *)]).
StripFieldNames ts =>
Rec ElField ts -> Rec Identity (Unlabeled ts)
stripNames
type CanDelete r rs = (V.RElem r rs (RIndex r rs), RDelete r rs V.⊆ rs)
rdel :: CanDelete r rs => Rec f rs -> Rec f (RDelete r rs)
rdel :: Rec f rs -> Rec f (RDelete r rs)
rdel = Rec f rs -> Rec f (RDelete r rs)
forall k1 k2 (rs :: [k1]) (ss :: [k1]) (f :: k2 -> *)
(record :: (k2 -> *) -> [k1] -> *) (is :: [Nat]).
(RecSubset record rs ss is, RecSubsetFCtx record f) =>
record f ss -> record f rs
V.rcast