Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding curry/uncurry, leftAdjunct/rightAdjunct #359

Closed
Icelandjack opened this issue Aug 27, 2018 · 2 comments · Fixed by #400
Closed

Adding curry/uncurry, leftAdjunct/rightAdjunct #359

Icelandjack opened this issue Aug 27, 2018 · 2 comments · Fixed by #400

Comments

@Icelandjack
Copy link
Contributor

For Data.Singleton.Sigma, these functions witness an isomorphism from Sigma being left adjoint

curry
  :: (Sigma k f -> b)
  -> (forall (a::k). Sing a -> f@@a -> b)
curry kont sing fa = kont (sing :&: fa)

uncurry
  :: (forall (a::k). Sing a -> f@@a -> b)
  -> (Sigma k f -> b)
uncurry kont ((fst :: Sing fst) :&: f_fst) = kont @fst fst f_st

Any interest in adding these with better names? There is also

unit :: Sing a -> f@@a -> Sigma k f
unit = curry id

counit :: Sigma k (ConstSym1 b) -> b
counit = projSigma2 id
@RyanGlScott
Copy link
Collaborator

I have no objection to a PR which adds curry or uncurry (although they should probably be named currySigma and uncurrySigma to match the existing naming conventions). There are already a number of existing utility functions in Data.Singleton.Sigma which generalize functions which work over non-dependent pairs, and these functions fit in quite nicely within that space.

I don't see much utility in having unit or counit. unit is just another way to write (:&:), and counit is just a less general version of projSigma2.

@RyanGlScott
Copy link
Collaborator

On second thought, I wonder if we should actually wait until (if?) #366 is implemented before going through with this. The reason is that we could actually make the types of currySigma and uncurrySigma more general:

type family Sing :: k -> Type

newtype WrappedSing (a :: k) = WrapSing (Sing a)
newtype SWrappedSing :: forall k (a :: k). WrappedSing a -> Type where
  SWrapSing :: forall k (a :: k) (ws :: WrappedSing a).
               Sing a -> SWrappedSing ws
type instance Sing = SWrappedSing

data Sigma (s :: Type) :: (s ~> Type) -> Type where
  (:&:) :: forall s t fst. Sing (fst :: s) -> t @@ fst -> Sigma s t
data SSigma :: forall s (t :: s ~> Type). Sigma s t -> Type where
  (:%&:) :: forall s t (fst :: s) (sfst :: Sing fst) (snd :: t @@ fst).
            Sing (WrapSing sfst) -> Sing snd -> SSigma (sfst :&: snd :: Sigma s t)
type instance Sing = SSigma

currySigma :: forall a (b :: a ~> Type) (c :: Sigma a b ~> Type).
              (forall (p :: Sigma a b). Sing p -> c @@ p)
           -> (forall (x :: a) (sx :: Sing x) (y :: b @@ x).
                 Sing (WrapSing sx) -> Sing y -> c @@ (sx :&: y))
currySigma f x y = f (x :%&: y)

uncurrySigma :: forall a (b :: a ~> Type) (c :: Sigma a b ~> Type).
                (forall (x :: a) (sx :: Sing x) (y :: b @@ x).
                   Sing (WrapSing sx) -> Sing y -> c @@ (sx :&: y))
             -> (forall (p :: Sigma a b). Sing p -> c @@ p)
uncurrySigma f (x :%&: y) = f x y

These more closely resemble how these functions are defined in Agda:

curry :  {a b c} {A : Set a} {B : A  Set b} {C : Σ A B  Set c} 
        ((p : Σ A B)  C p) 
        ((x : A)  (y : B x)  C (x , y))
curry f x y = f (x , y)

uncurry :  {a b c} {A : Set a} {B : A  Set b} {C : Σ A B  Set c} 
          ((x : A)  (y : B x)  C (x , y)) 
          ((p : Σ A B)  C p)
uncurry f (x , y) = f x y

RyanGlScott added a commit that referenced this issue Mar 20, 2019
[ci skip]
RyanGlScott added a commit that referenced this issue Jul 11, 2019
* `SSigma`, the singleton type for `Sigma`, has been added.
  This fixes #366.
* A `Show` instance has been added for `Sigma` (and `SSigma`) by
  using copious amounts of quantified constraints. The behavior of
  these instances closely resembles the `Show` implementation for
  `DPair` in Idris' standard library:
  https://github.com/idris-lang/Idris-dev/blob/dbe521ff74189df85121abe454f86894de7fd75c/libs/prelude/Prelude/Show.idr#L195-L196
* New functions `fstSigma` and `sndSigma` (as well as their
  type-level counterparts) have been added. To avoid being a
  duplicate of `fstSigma`, `projSigma1` has been redefined to have a
  new type signature that uses continuation-passing style, much like
  its cousin `projSigma2`.
* New functions `currySigma` and `uncurrySigma` have been added. This
  fixes #359 and supersedes #360.
RyanGlScott added a commit that referenced this issue Jul 12, 2019
* `SSigma`, the singleton type for `Sigma`, has been added.
  This fixes #366.
* A `Show` instance has been added for `Sigma` (and `SSigma`) by
  using copious amounts of quantified constraints. The behavior of
  these instances closely resembles the `Show` implementation for
  `DPair` in Idris' standard library:
  https://github.com/idris-lang/Idris-dev/blob/dbe521ff74189df85121abe454f86894de7fd75c/libs/prelude/Prelude/Show.idr#L195-L196
* New functions `fstSigma` and `sndSigma` (as well as their
  type-level counterparts) have been added. To avoid being a
  duplicate of `fstSigma`, `projSigma1` has been redefined to have a
  new type signature that uses continuation-passing style, much like
  its cousin `projSigma2`.
* New functions `currySigma` and `uncurrySigma` have been added. This
  fixes #359 and supersedes #360.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants