Skip to content

Instantly share code, notes, and snippets.

@CarstenKoenig
Created July 7, 2018 20:31
Show Gist options
  • Save CarstenKoenig/713b08809b37525595fd566f5487cafb to your computer and use it in GitHub Desktop.
Save CarstenKoenig/713b08809b37525595fd566f5487cafb to your computer and use it in GitHub Desktop.
nice Haskell Type - Riddle
{-# LANGUAGE RankNTypes, DeriveFunctor #-}
module Riddle where
type T a b c = forall f . Functor f => (a -> f b) -> f c
to :: (a, b -> c) -> T a b c
to (a, b_c) f = fmap b_c (f a)
from :: T a b c -> (a, b -> c)
from f = (a, b_c)
where
a = unconst $ f Const
-- ignore `a` and use the functor `b -> _`
-- to tease out a `b -> c` from (\_ b -> b)
b_c = f (const id)
newtype Const c a = Const { unconst :: c }
deriving Functor
@CarstenKoenig
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment