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

module Dovetail.Core.Data.Show where

import Data.Foldable (fold)
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Vector (Vector)
import Data.Vector qualified as 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
"Data.Show"
  
      showImpl :: forall a. Show a => a -> Eval ctx Text
      showImpl :: a -> Eval ctx Text
showImpl = Text -> Eval ctx Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Eval ctx Text) -> (a -> Text) -> a -> Eval ctx Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Show a => a -> String
forall a. Show a => a -> String
show @a

  [Env ctx] -> Env ctx
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
    [ -- showIntImpl :: Int -> String
      ModuleName -> Text -> (Integer -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Integer -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showIntImpl"
        (Show Integer => Integer -> Eval ctx Text
forall a. Show a => a -> Eval ctx Text
showImpl @Integer)
    , -- showNumberImpl :: Number -> String
      ModuleName -> Text -> (Double -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Double -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showNumberImpl"
        (Show Double => Double -> Eval ctx Text
forall a. Show a => a -> Eval ctx Text
showImpl @Double)
    , -- showCharImpl :: Char -> String
      ModuleName -> Text -> (Char -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Char -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showCharImpl"
        (Show Char => Char -> Eval ctx Text
forall a. Show a => a -> Eval ctx Text
showImpl @Char)
    , -- showStringImpl :: String -> String
      ModuleName -> Text -> (Text -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showStringImpl"
        (Show Text => Text -> Eval ctx Text
forall a. Show a => a -> Eval ctx Text
showImpl @Text)
    , -- showArrayImpl :: forall a. (a -> String) -> Array a -> String
      ModuleName
-> Text
-> ((Value ctx -> Eval ctx Text)
    -> Vector (Value ctx) -> Eval ctx Text)
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @((Value ctx -> Eval ctx Text) -> Vector (Value ctx) -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showArrayImpl"
        \Value ctx -> Eval ctx Text
_show Vector (Value ctx)
xs -> 
          (Vector Text -> Text) -> Eval ctx (Vector Text) -> Eval ctx Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap 
            (\Vector Text
ys -> Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
Text.intercalate Text
"," (Vector Text -> [Text]
forall a. Vector a -> [a]
Vector.toList Vector Text
ys) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]")
            ((Value ctx -> Eval ctx Text)
-> Vector (Value ctx) -> Eval ctx (Vector Text)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Value ctx -> Eval ctx Text
_show Vector (Value ctx)
xs)
    , -- cons :: forall a. a -> Array a -> Array a
      ModuleName
-> Text
-> (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 @(Value ctx -> Vector (Value ctx) -> Eval ctx (Vector (Value ctx)))
        ModuleName
_ModuleName Text
"cons"
        \Value ctx
hd Vector (Value ctx)
tl ->
          Vector (Value ctx) -> Eval ctx (Vector (Value ctx))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value ctx -> Vector (Value ctx) -> Vector (Value ctx)
forall a. a -> Vector a -> Vector a
Vector.cons Value ctx
hd Vector (Value ctx)
tl)
    , -- join :: String -> Array String -> String
      ModuleName
-> Text -> (Text -> Vector Text -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Vector Text -> Eval ctx Text)
        ModuleName
_ModuleName Text
"join"
        \Text
sep Vector Text
xs ->
          Text -> Eval ctx Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> [Text] -> Text
Text.intercalate Text
sep (Vector Text -> [Text]
forall a. Vector a -> [a]
Vector.toList Vector Text
xs))
    ]