{-# OPTIONS -Wno-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.V.Linear.Internal.Instances where
import qualified Data.Functor.Linear.Internal.Applicative as Data
import qualified Data.Functor.Linear.Internal.Functor as Data
import qualified Data.Functor.Linear.Internal.Traversable as Data
import Data.V.Linear.Internal (V (..))
import qualified Data.V.Linear.Internal as V
import qualified Data.Vector as Vector
import GHC.TypeLits
import Prelude.Linear.Internal
import qualified Unsafe.Linear as Unsafe
import qualified Prelude
instance Data.Functor (V n) where
fmap :: forall a b. (a %1 -> b) -> V n a %1 -> V n b
fmap = forall a b (n :: Nat). (a %1 -> b) -> V n a %1 -> V n b
V.map
instance (KnownNat n) => Data.Applicative (V n) where
pure :: forall a. a -> V n a
pure = forall (n :: Nat) a. KnownNat n => a -> V n a
V.pure
V n (a %1 -> b)
a <*> :: forall a b. V n (a %1 -> b) %1 -> V n a %1 -> V n b
<*> V n a
b = V n (a %1 -> b)
a forall (n :: Nat) a b. V n (a %1 -> b) %1 -> V n a %1 -> V n b
V.<*> V n a
b
instance (KnownNat n) => Prelude.Applicative (V n) where
pure :: forall a. a -> V n a
pure = forall (n :: Nat) a. KnownNat n => a -> V n a
V.pure
V Vector (a -> b)
fs <*> :: forall a b. V n (a -> b) -> V n a -> V n b
<*> V Vector a
xs = forall (n :: Nat) a. Vector a -> V n a
V forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> Vector a -> Vector b -> Vector c
Vector.zipWith forall a b. (a -> b) -> a -> b
($) Vector (a -> b)
fs Vector a
xs
instance (KnownNat n) => Data.Traversable (V n) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a %1 -> f b) -> V n a %1 -> f (V n b)
traverse a %1 -> f b
f (V Vector a
xs) =
(forall (n :: Nat) a. Vector a -> V n a
V forall b c a. (b %1 -> c) -> (a %1 -> b) -> a -> c
. forall a b. (a -> b) %1 -> a -> b
Unsafe.toLinear (forall a. Int -> [a] -> Vector a
Vector.fromListN (forall (n :: Nat). KnownNat n => Int
V.theLength @n)))
forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a %1 -> f b) -> t a %1 -> f (t b)
Data.traverse a %1 -> f b
f (forall a b. (a -> b) %1 -> a -> b
Unsafe.toLinear forall a. Vector a -> [a]
Vector.toList Vector a
xs)