Skip to content

Instantly share code, notes, and snippets.

@tonymorris

tonymorris/typeclasses.hs Secret

Created Nov 23, 2020
Embed
What would you like to do?
{-# LANGUAGE RankNTypes #-}
-- as a data type
data Functor1 f =
Functor2 { fmap1 :: forall a b. (a -> b) -> f a -> f b }
-- as a type-class
class Functor2 f where
fmap2 :: (a -> b) -> f a -> f b
flip1 :: Functor1 f -> f (a -> b) -> a -> f b
flip1 f x a = fmap1 f (\k -> k a) x
flip2 :: Functor2 f => f (a -> b) -> a -> f b
flip2 x a = fmap2 (\k -> k a) x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment