setAttributes :: [SetAttribute]  -- ^ Which attributes to set
              -> Ext Record      -- ^ New record
              -> Ext Record      -- ^ Older record
              -> Ext Record
setAttributes sets newRecord oldRecord = foldl apply oldRecord sets
  where
    apply :: Ext Record -> SetAttribute -> Ext Record
    apply record (targetName := src)
      | targetName == "date" = record {getDate = getDate newRecord}
      | SExactly "date" <- src = 
          setAttr targetName (Exactly $ pPrint $ getDate newRecord) record
      | SOptional "date" <- src = 
          setAttr targetName (Optional $ pPrint $ getDate newRecord) record
      | SExactly sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Exactly value) record
      | SOptional sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Optional value) record
      | SFixed string <- src = 
          setAttr targetName (Exactly string) record
      | otherwise = record
setAttributes :: [SetAttribute]  -- ^ Which attributes to set
              -> Ext Record      -- ^ New record
              -> Ext Record      -- ^ Older record
              -> Ext Record
setAttributes sets newRecord oldRecord = foldl apply oldRecord sets
  where
    apply :: Ext Record -> SetAttribute -> Ext Record
    apply record (targetName := src)
      | targetName == "date" = record {getDate = getDate newRecord}
      | SExactly "date" <- src = 
          setAttr targetName (Exactly $ pPrint $ getDate newRecord) record
      | SOptional "date" <- src = 
          setAttr targetName (Optional $ pPrint $ getDate newRecord) record
      | SExactly sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Exactly value) record
      | SOptional sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Optional value) record
      | SFixed string <- src = 
          setAttr targetName (Exactly string) record
      | otherwise = record
setAttributes sets newRecord oldRecord = foldl apply oldRecord sets
  where
    apply :: Ext Record -> SetAttribute -> Ext Record
    apply record (targetName := src)
      | targetName == "date" = record {getDate = getDate newRecord}
      | SExactly "date" <- src = 
          setAttr targetName (Exactly $ pPrint $ getDate newRecord) record
      | SOptional "date" <- src = 
          setAttr targetName (Optional $ pPrint $ getDate newRecord) record
      | SExactly sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Exactly value) record
      | SOptional sourceName <- src = 
          case getAttr sourceName newRecord of
            Nothing -> record
            Just value -> setAttr targetName (Optional value) record
      | SFixed string <- src = 
          setAttr targetName (Exactly string) record
      | otherwise = record