Is there a way to write a function with this signature?

I have a function that is doing something currently with specific data types. I was wondering if I can make this a general. Here is a generalized version of his signature:

f :: Monad m => ((a -> b) -> c -> d) -> (a -> m b) -> m c -> m d

If the above cannot be recorded, perhaps a more limited version can?

f2 :: Monad m => ((a -> a) -> b -> b) -> (a -> m a) -> m b -> m b
+4
source share
2 answers

No, this is not possible, at least without unreasonable or unsafe operations.

The argument is essentially similar to this : we are using a ftype of habitat that, as we know, cannot be populated.

Assume that exists

f :: Monad m => ((a -> b) -> c -> d) -> (a -> m b) -> m c -> m d

Specialize c ~ ()

f :: Monad m => ((a -> b) -> () -> d) -> (a -> m b) -> m () -> m d

Hence

(\g h -> f (\x _ -> g x) h (return ()))
  :: Monad m => ((a -> b) -> d) -> (a -> m b) -> m d

Speciazlize d ~ a.

(\g h -> f (\x _ -> g x) h (return ()))
  :: Monad m => ((a -> b) -> a) -> (a -> m b) -> m a

Speclialize m ~ Cont t

(\g h -> runCont $ f (\x _ -> g x) (cont . h) (return ()))
  :: ((a1 -> b) -> a) -> (a1 -> (b -> r) -> r) -> (a -> r) -> r

Take h = const

(\g -> runCont $ f (\x _ -> g x) (cont . const) (return ()))
  :: ((r -> b) -> a) -> (a -> r) -> r

Hence

(\g -> runCont (f (\x _ -> g x) (cont . const) (return ())) id)
  :: ((r -> b) -> r) -> r

, ((r -> b) -> r) -> r , , - . ((A -> B) -> A) -> A , , , .

, f.


f2 :: Monad m => ((a -> a) -> b -> b) -> (a -> m a) -> m b -> m b

f2 = \ g h x -> x

, , .

+4

. c , a (a -> b). a, a -

(forall f. Functor f => ((a -> f b) -> c -> f d)

f.

, f , , ((a -> b) -> c -> d), , , - .

+2

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


All Articles