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

module Dovetail.Core.Data.Enum where

import Data.Char (chr, ord)
import Data.Foldable (fold)
import Dovetail
import Dovetail.Evaluate (builtIn)
import Language.PureScript qualified as P

env :: forall ctx. Env ctx
env :: Env ctx
env = do
  let _ModuleName :: ModuleName
_ModuleName = Text -> ModuleName
P.ModuleName Text
"Data.Enum"

  [Env ctx] -> Env ctx
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
    [ -- toCharCode :: Char -> Int
      ModuleName -> Text -> (Char -> Eval ctx Integer) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Char -> Eval ctx Integer)
        ModuleName
_ModuleName Text
"toCharCode"
        \Char
c ->
          Integer -> Eval ctx Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
ord Char
c))
      -- fromCharCode :: Int -> Char
    , ModuleName -> Text -> (Integer -> Eval ctx Char) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Integer -> Eval ctx Char)
        ModuleName
_ModuleName Text
"fromCharCode"
        \Integer
i ->
          Char -> Eval ctx Char
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> Char
chr (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i))
    ]