Created
March 27, 2018 15:06
-
-
Save mizunashi-mana/0b7db5fb26704d47c42234a377fdd777 to your computer and use it in GitHub Desktop.
:~>の例
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 #-} | |
{-# 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