Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add combine :: Adjunction f u => u a -> f b -> (a, b) #1

Closed
sjoerdvisscher opened this Issue January 16, 2012 · 5 comments

2 participants

Sjoerd Visscher Edward Kmett
Sjoerd Visscher
Collaborator

When playing with a bit of code I needed a combine function, which I think should be part of the adjunctions library.

combine :: Adjunction f u => u a -> f b -> (a, b)
combine ua = rightAdjunct (\b -> fmap (\a -> (a, b)) ua)

https://gist.github.com/1621224

greetings,
Sjoerd Visscher

Edward Kmett
Owner
Sjoerd Visscher
Collaborator

Nice, zapWith is even better. (I don't know about the newtype.)

But take your time, it was just a bit of toy code, and I don't think it adds anything useful to the enumerator/conduit/pipe discussion.

Edward Kmett
Owner
Sjoerd Visscher
Collaborator

What about just a type synonym

type Zap f g = forall a b c. (a -> b -> c) -> f a -> g b -> c

zap :: Zap f g -> f (a -> b) -> g a -> b
zap z = z id

flipZap :: Zap f g -> Zap g f 
flipZap z f a b = z (flip f) b a

composeZap :: Zap f g -> Zap h i -> Zap (Compose f h) (Compose g i) 
composeZap u v f (Compose a) (Compose b) = u (v f) a b
Edward Kmett
Owner
Sjoerd Visscher sjoerdvisscher closed this February 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.