{-# LANGUAGE BlockArguments      #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications    #-}
{-# LANGUAGE ViewPatterns        #-}

module Dovetail.Core.Control.Apply where

import Data.Vector (Vector)
import Dovetail
import Dovetail.Evaluate (builtIn)

env :: forall ctx. Env ctx
env :: Env ctx
env = do
  let _ModuleName :: ModuleName
_ModuleName = Text -> ModuleName
ModuleName Text
"Control.Apply"

  -- arrayApply :: forall a b. Array (a -> b) -> Array a -> Array b
  ModuleName
-> Text
-> (Vector (Value ctx -> Eval ctx (Value ctx))
    -> Vector (Value ctx) -> Eval ctx (Vector (Value ctx)))
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Vector (Value ctx -> Eval ctx (Value ctx)) -> Vector (Value ctx) -> Eval ctx (Vector (Value ctx)))
    ModuleName
_ModuleName Text
"arrayApply"
    \Vector (Value ctx -> Eval ctx (Value ctx))
fs Vector (Value ctx)
xs -> Vector (Eval ctx (Value ctx)) -> Eval ctx (Vector (Value ctx))
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (Vector (Value ctx -> Eval ctx (Value ctx))
fs Vector (Value ctx -> Eval ctx (Value ctx))
-> Vector (Value ctx) -> Vector (Eval ctx (Value ctx))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Vector (Value ctx)
xs)