Skip to content

Instantly share code, notes, and snippets.

@mizunashi-mana
Created March 27, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizunashi-mana/0b7db5fb26704d47c42234a377fdd777 to your computer and use it in GitHub Desktop.
Save mizunashi-mana/0b7db5fb26704d47c42234a377fdd777 to your computer and use it in GitHub Desktop.
:~>の例
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module NatTrans where
import Data.Foldable
import Data.Functor.Identity
newtype f :~> g = NT
{ unNT :: forall a. f a -> g a
}
type f ~> g = forall a. f a -> g a
-- | Alias of 'toList :: forall f a. Foldable f => f a -> [a]'
--
-- >>> toListNt (Just True)
-- [True]
--
toListNt :: Foldable f => f ~> []
toListNt = toList
-- | Alias of 'toListNt'
--
-- >>> unNT toListNT (Just True)
-- [True]
--
toListNT :: Foldable f => f :~> []
toListNT = NT toListNt
-- |
--
-- >>> unNT (toRightIdentNT Just) (Identity True)
-- Just True
--
toRightIdentNT :: (forall a. a -> f a) -> Identity :~> f
toRightIdentNT f = NT (f . runIdentity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment