Created
June 4, 2015 10:04
-
-
Save pacak/a3ece68903c617f3172d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
class Dual f g | f -> g, g -> f where | |
zap :: (a -> b -> c) -> f a -> g b -> c | |
data PrintF a = PrintF String a deriving Functor | |
data CoPrintF a = CoPrintF { coPrint :: String -> a } deriving Functor | |
instance Dual PrintF CoPrintF where | |
zap f (PrintF msg k) (CoPrintF prn) = f k (prn msg) | |
pr = PrintF "Hello world" id | |
copr = CoPrintF print | |
main = zap ($) pr copr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment