Skip to content

Instantly share code, notes, and snippets.

@paulvictor
Created July 17, 2018 06:40
Show Gist options
  • Select an option

  • Save paulvictor/418c74aba40e0ff989440e19eb2c66b8 to your computer and use it in GitHub Desktop.

Select an option

Save paulvictor/418c74aba40e0ff989440e19eb2c66b8 to your computer and use it in GitHub Desktop.
Record subset
class RowSubset (row :: # Type) (xs :: RowList) (subrow :: # Type) | xs -> subrow where
subsetImpl :: RLProxy xs -> {|row} -> {|subrow}
instance nilRowSubset :: RowSubset row Nil () where subsetImpl _ _ = {}
instance consRowSubset
::
( IsSymbol sym
, Cons sym a subrowWithoutSym subrowWithSym
, Cons sym a srcWithoutSym src
, Lacks sym subrowWithoutSym
, RowSubset src rl subrowWithoutSym
) => RowSubset src (Cons sym a rl) subrowWithSym where
subsetImpl _ src = insert (SProxy :: SProxy sym) (get (SProxy :: SProxy sym) src) (subsetImpl (RLProxy :: RLProxy rl) src)
subsetRow
:: ∀ rl subR src
. ListToRow rl subR
=> RowToList subR rl
=> RowSubset src rl subR
=> {|src}
-> RProxy subR
-> {|subR}
subsetRow src _ = subsetImpl (RLProxy :: RLProxy rl) src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment