Is it possible to “overclock” the full quantifier?

Suppose we have a constructor of type f that accepts two types using the pair created by DataKinds.

forall (f :: (ka, kb) -> *)

Then I can implement a function forwardthat is similar to curryfor a quantifier forall:

forward :: forall (f :: (ka, kb) -> *).
           (forall (ab :: (ka, kb)).     f ab) ->
           (forall (a :: ka) (b :: kb).  f '(a, b))
forward x = x

However, the inverse function is problematic:

backward :: forall (f :: (*, *) -> *).
            (forall (a :: *) (b :: *). f '(a, b)) ->
            (forall (ab :: (*, *)). f ab)
backward x = x

GHC 8.0.1 contains an error message:

    • Couldn't match type 'ab' with '' (a0, b0) '
      'ab' is a rigid type variable bound by
        the type signature for:
          backward :: forall (ab :: (*, *)). (forall a b. f '(a, b)) -> f ab
        at: 6: 116
      Expected type: f ab
        Actual type: f '(a0, b0)
    • In the expression: x
      In an equation for 'backward': backward x = x

. ? GHC?

+4
1

, , , ab "" . ( ):

type family Fst (x :: (k1, k2)) :: k1 where
  Fst '(t1, t2) = t1

type family Snd (x :: (k1, k2)) :: k2 where
  Snd '(t1, t2) = t2

backward :: forall (f :: (*, *) -> *) (ab :: (*, *)) proxy .
            proxy ab ->
            (forall (a :: *) (b :: *). f '(a, b)) ->
            f '(Fst ab, Snd ab)
backward _ x = x

, , .

newtype Curry f x y = Curry (f '(x,y))

data Uncurry f xy where
  Uncurry :: f x y -> f '(x, y)
+6

Source: https://habr.com/ru/post/1653828/


All Articles