{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
module PlutusTx.Functor (Functor(..), (<$>), (<$)) where
import Control.Applicative (Const (..))
import Data.Functor.Identity (Identity (..))
import PlutusTx.Base
import PlutusTx.Either (Either (..))
import Prelude (Maybe (..))
class Functor f where
fmap :: (a -> b) -> f a -> f b
infixl 4 <$>
{-# INLINABLE (<$>) #-}
(<$>) :: Functor f => (a -> b) -> f a -> f b
<$> :: forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
(<$>) a -> b
f f a
fa = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f f a
fa
infixl 4 <$
{-# INLINABLE (<$) #-}
(<$) :: Functor f => a -> f b -> f a
<$ :: forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$) a
a f b
fb = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const a
a) f b
fb
instance Functor [] where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> [a] -> [b]
fmap a -> b
f [a]
l = case [a]
l of
[] -> []
a
x:[a]
xs -> a -> b
f a
x forall a. a -> [a] -> [a]
: forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f [a]
xs
instance Functor Maybe where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> Maybe a -> Maybe b
fmap a -> b
f (Just a
a) = forall a. a -> Maybe a
Just (a -> b
f a
a)
fmap a -> b
_ Maybe a
Nothing = forall a. Maybe a
Nothing
instance Functor (Either c) where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> Either c a -> Either c b
fmap a -> b
f (Right a
a) = forall a b. b -> Either a b
Right (a -> b
f a
a)
fmap a -> b
_ (Left c
c) = forall a b. a -> Either a b
Left c
c
instance Functor ((,) c) where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> (c, a) -> (c, b)
fmap a -> b
f (c
c, a
a) = (c
c, a -> b
f a
a)
instance Functor Identity where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> Identity a -> Identity b
fmap a -> b
f (Identity a
a) = forall a. a -> Identity a
Identity (a -> b
f a
a)
instance Functor (Const m) where
{-# INLINABLE fmap #-}
fmap :: forall a b. (a -> b) -> Const m a -> Const m b
fmap a -> b
_ (Const m
c) = forall {k} a (b :: k). a -> Const a b
Const m
c