Skip to content

Instantly share code, notes, and snippets.

@andrewthad
Created October 7, 2019 14:43
Show Gist options
  • Save andrewthad/b62e59411d6914770d1d7d96301252bb to your computer and use it in GitHub Desktop.
Save andrewthad/b62e59411d6914770d1d7d96301252bb to your computer and use it in GitHub Desktop.
ECS Records
module Record where
-- This approach gives us everything we want except for a type-safe
-- way to project out subsets of columns. For these kinds of projections,
-- the user will need to manually project out each column, upcast them
-- to uncompressed arrays (if they aren't absent), logical AND any mask
-- vectors, and then pick the valid rows from the columns. This is
-- inconvenient, but this kind of projection is a niche use that currently
-- only happens in insight.
data Representation
= Unsigned128
| Signed64
| Bytes
data Atom
= 'Number
| 'Ip
| 'Keyword
-- There will be at least 100 fields
data Fields f = Field
{ port :: f 'Number
, ip :: f 'Ip
, name :: f 'Keyword
}
data Prefixes a = Prefixes
{ source :: a
, destination :: a
}
data Nesting f = Nesting
{ fields :: Fields f
, prefixes :: Prefixes (Maybe (Nesting f))
}
newtype Record = Record (Nesting Column)
newtype Query = Query (Nesting Predicate)
data Encoding = Encoding (Prefixes Text) (Fields (Product (Const Text) EncodeColumn))
-- Boilerplate required. All three of these require writing out every field.
-- It may be possible to use TemplateHaskell to avoid tweaking these all by
-- hand every time a field is added. There are other useful variants
-- (e.g. an effectful zip), but they can be written as compositions of
-- these core primitives.
pureFields :: (forall x. f x) -> Fields f
traverseFields :: Applicative h => (forall x. f x -> h (g x)) -> Fields f -> h (Fields g)
zipFields :: (forall x. f x -> g x -> h x) -> Fields f -> Fields g -> Fields h
purePrefixes :: a -> Prefixes a
traversePrefixes :: Applicative h => (a -> h b) -> Prefixes a -> h (Prefixes b)
zipPrefixes :: (a -> b -> c) -> Prefixes a -> Prefixes b -> Prefixes c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment