Mikolaj / horde-ad

Higher Order Reverse Derivatives Efficiently - Automatic Differentiation library based on the paper "Provably correct, asymptotically efficient, higher-order reverse-mode automatic differentiation"
BSD 3-Clause "New" or "Revised" License
33 stars 6 forks source link

Generalize HordeAd.External.Adaptor from [a] to Traversable a and also to MonoTraversable #73

Open Mikolaj opened 2 years ago

Mikolaj commented 2 years ago

This would need to be changed a lot, because for definition

instance (AdaptableDomains a, Traversable t)
         => AdaptableDomains (t a) where
  type Scalar (t a) = Scalar a
  toDomains l = unefined  -- use unzip x = (fmap fst x, fmap snd x), etc.
  fromDomains lInit source =
    let f = swap . flip fromDomains
    in swap $ mapAccumL f source lInit

I'm getting errors like

src/HordeAd/External/Adaptor.hs:237:8: error:
    Conflicting family instance declarations:
      Scalar (t a) = Scalar a
        -- Defined at src/HordeAd/External/Adaptor.hs:237:8
      Scalar (a, b, c) = Scalar a
        -- Defined at src/HordeAd/External/Adaptor.hs:271:8
    |
237 |   type Scalar (t a) = Scalar a
    |        ^^^^^^

src/HordeAd/External/Adaptor.hs:245:8: error:
    Conflicting family instance declarations:
      Value (t a) = t (Value a)
        -- Defined at src/HordeAd/External/Adaptor.hs:245:8
      Value (a, b) = (Value a, Value b)
        -- Defined at src/HordeAd/External/Adaptor.hs:312:8
    |
245 |   type Value (t a) = t (Value a)
    |        ^^^^^