{-

doctest -DDOCTEST SzInfer.hs

doctest -DDOCTEST -XFlexibleContexts SzInfer.hs


 -}


{-# LANGUAGE TypeSynonymInstances #-}

{-# LANGUAGE FlexibleInstances #-}

{-# LANGUAGE OverloadedStrings #-}


{-# LANGUAGE CPP #-}




-- {-# OPTIONS_GHC -cpp -DDOCTEST #-}

-- {-# OPTIONS_GHC -cpp -DDEBUG #-}

-- use w/ caution
-- {-# OPTIONS_GHC -Wno-name-shadowing #-}

-- {-# OPTIONS_GHC -fno-warn-orphans #-}

{-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# OPTIONS_GHC -Wno-orphans #-}


module PrettySSubst where


#ifdef DEBUG
import Debug.Trace
#else
import Debug.NoTrace ()
#endif 

-- import qualified Data.Map as Map
import qualified Data.Map as M

import Data.Text.Prettyprint.Doc

-- import PrettyBasic
import PrettyCommon
-- import PrettyBasic

import PrettySize


import Control.Monad.Identity

import Data.Text (Text, unpack)

import Utils (names)


-- import New (Ctx)
import SSubst (SSubst)

import Size (Size(..))



#ifdef DOCTEST

-- -- import qualified Data.Map as M
import Smart (lam)


#endif





prettySSubst :: (Applicative f)
  => SSubst t -> [String] -> Int -> (t -> Int -> f (Doc ann)) -> f (Doc ann)
prettySSubst  m vars prec kt =
  -- (\dps -> hcat dps ) <$> traverse (\p -> prettykvpair p vars prec kt ka) (M.toList m)

  (\dps -> encloseSep lbracket rbracket comma dps) <$> traverse (\p -> prettykvpair p vars prec kt) (M.toList m)

  where
    prettykvpair (k,v@SSum{}) vars prec kt  = (\dk dv -> (parens dv) <> "/" <> dk) <$> prettySVar k vars prec kt <*> prettySize v vars prec kt
    prettykvpair (k,v) vars prec kt  = (\dk dv -> dv <> "/" <> dk) <$> prettySVar k vars prec kt <*> prettySize v vars prec kt


instance Pretty (SSubst Text) where

  pretty m = runIdentity $ prettySSubst m names' (-1) (pure . pure . pretty)
    where names' = names


instance Pretty (SSubst String) where

  pretty m = runIdentity $ prettySSubst m names' (-1) (pure . pure . pretty )
    where names' = names