chrisdone-archive / labels

Declare and access tuple fields with labels
61 stars 8 forks source link

how to merge two label record? #16

Open clojurians-org opened 5 years ago

clojurians-org commented 5 years ago

currently i only can find cons function to expand record. it's possible to merge two label record, and merge the same field?

*Main Labels> get #b (#a := 3, #b := "c", #a:="d")
"c"
*Main Labels> cons (#a := "d") (#a := 3)
(#a := "d",#a := 3)
*Main Labels> get #a (#a := 3, #b := "c", #a:="d")

<interactive>:65:1: error:
    • Overlapping instances for Has
                                  "a" value ("a" := value, "b" := value0, "a" := value)
      Matching givens (or their superclasses):
        Has "a" value ("a" := value, "b" := value1, "a" := value)
          bound by the inferred type for ‘it’:
                     forall value value1.
                     (Num value,
                      Has "a" value ("a" := value, "b" := value1, "a" := value),
                      Data.String.IsString value1, Data.String.IsString value) =>
                     value
          at <interactive>:65:1-36
      Matching instances:
        instance Has l a (l := a, u2, u3) -- Defined in ‘Labels.Internal’
        instance Has l a (u1, u2, l := a) -- Defined in ‘Labels.Internal’
    • In the ambiguity check for the inferred type for ‘it’
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      When checking the inferred type
        it :: forall value1 value2.
              (Num value1,
               Has "a" value1 ("a" := value1, "b" := value2, "a" := value1),
               Data.String.IsString value2, Data.String.IsString value1) =>
              value1
clojurians-org commented 5 years ago

it seems the ++ operate is very hard to implement for tuple as two tuple is n^2 combinator TH. so i think exist the two way to resolve it: 1) conver to Heterogeneous lists, and ++, and convert back. 2) offer special get function for (labels string), so we can use labels information to extract all fields