Skip to content

Commit

Permalink
Merge pull request #120 from zkFold/eitan-field-io
Browse files Browse the repository at this point in the history
more FunctionSpace instances
  • Loading branch information
vlasin authored May 27, 2024
2 parents ce600f4 + 8acc5a0 commit 2dcc420
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/ZkFold/Base/Algebra/Basic/VectorSpace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,48 @@ class

type family InputSpace a f where
InputSpace a (x a -> f) = x :*: InputSpace a f
InputSpace a (a -> f) = Identity :*: InputSpace a f
InputSpace a (y a) = U1
InputSpace a a = U1

type family OutputSpace a f where
OutputSpace a (x a -> f) = OutputSpace a f
OutputSpace a (a -> f) = OutputSpace a f
OutputSpace a (y a) = y
OutputSpace a a = Identity

instance {-# OVERLAPPABLE #-}
instance
( VectorSpace a y
, OutputSpace a (y a) ~ y
, InputSpace a (y a) ~ U1
) => FunctionSpace a (y a) where
uncurryV f _ = f
curryV k = k U1

instance {-# OVERLAPPING #-}
instance
( InputSpace a a ~ U1
, OutputSpace a a ~ Identity
) => FunctionSpace a a where
uncurryV a _ = Identity a
curryV k = runIdentity (k U1)

instance
( VectorSpace a x
, OutputSpace a (x a -> f) ~ OutputSpace a f
, InputSpace a (x a -> f) ~ x :*: InputSpace a f
, FunctionSpace a f
) => FunctionSpace a (x a -> f) where
uncurryV f i = uncurryV (f (pi1 i)) (pi2 i)
where
pi1 (u :*: _) = u
pi2 (_ :*: v) = v

uncurryV f (i :*: j) = uncurryV (f i) j
curryV k x = curryV (k . (:*:) x)

instance
( OutputSpace a (a -> f) ~ OutputSpace a f
, InputSpace a (a -> f) ~ Identity :*: InputSpace a f
, FunctionSpace a f
) => FunctionSpace a (a -> f) where
uncurryV f (Identity i :*: j) = uncurryV (f i) j
curryV k x = curryV (k . (:*:) (Identity x))

composeFunctions
:: ( FunctionSpace a g
, FunctionSpace a f
Expand Down

0 comments on commit 2dcc420

Please sign in to comment.