Skip to content

Instantly share code, notes, and snippets.

@pacak
Created June 4, 2015 10:04
Show Gist options
  • Save pacak/a3ece68903c617f3172d to your computer and use it in GitHub Desktop.
Save pacak/a3ece68903c617f3172d to your computer and use it in GitHub Desktop.
{-# 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