Created
July 7, 2018 20:31
-
-
Save CarstenKoenig/713b08809b37525595fd566f5487cafb to your computer and use it in GitHub Desktop.
nice Haskell Type - Riddle
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
straight from this tweet: https://twitter.com/Iceland_jack/status/1014745561642172417