module TypeMachine.TH.Internal.Utils (capitalize, getRecordConstructorVars) where

import Data.Char (toUpper)
import Language.Haskell.TH hiding (Type, reifyType)

-- | Capitalize the first letter of a string
capitalize :: String -> String
capitalize :: String -> String
capitalize (Char
c : String
cs) = Char -> Char
toUpper Char
c Char -> String -> String
forall a. a -> [a] -> [a]
: String
cs
capitalize String
cs = String
cs

-- From a 'DataD''s constructors, returns its unique constructor's fields.
--
-- Fails if the list of 'Con' does not have exactly one record constructor
getRecordConstructorVars :: (MonadFail m) => [Con] -> m [VarBangType]
getRecordConstructorVars :: forall (m :: * -> *). MonadFail m => [Con] -> m [VarBangType]
getRecordConstructorVars [RecC Name
_ [VarBangType]
vbt] = [VarBangType] -> m [VarBangType]
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return [VarBangType]
vbt
getRecordConstructorVars [Con]
_ = String -> m [VarBangType]
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Type-Machine Error: Expected type to have exactly one Record constructor"

-- TODO I don't like passing [Con] as parameter. Might need to redesign this function