Generalize elemOfString into elemOf'

This commit is contained in:
Niels G. W. Serup 2024-10-06 16:23:57 +02:00
parent 08fc0f30e4
commit 43f2cef419
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
2 changed files with 8 additions and 6 deletions

View File

@ -7,7 +7,7 @@ module Function
, fileComponents , fileComponents
, lowerString , lowerString
, elemOf , elemOf
, elemOfString , elemOf'
, makeTemplate , makeTemplate
, applyTemplate , applyTemplate
, toText , toText
@ -79,10 +79,12 @@ lowerString :: TokenableTo String a => a -> DepGenM (Token String)
lowerString a = runFunction LowerString =<< toToken a lowerString a = runFunction LowerString =<< toToken a
class (Show w, Lift w) => WitnessFor w t | w -> t class (Show w, Lift w) => WitnessFor w t | w -> t, t -> w where
witnessValue :: w
data StringType = StringType deriving (Show, Lift) data StringType = StringType deriving (Show, Lift)
instance WitnessFor StringType String instance WitnessFor StringType String where
witnessValue = StringType
data ElemOf a where ElemOf :: WitnessFor w a => w -> ElemOf a data ElemOf a where ElemOf :: WitnessFor w a => w -> ElemOf a
deriving instance Show (ElemOf a) deriving instance Show (ElemOf a)
@ -93,8 +95,8 @@ instance (Show a, Lift a, Valuable a, Eq a) => IsFunction (ElemOf a) (a, [a]) Bo
elemOf :: (Show t, Lift t, Valuable t, Eq t, TokenableTo t a, TokenableTo [t] b, WitnessFor w t) => w -> a -> b -> DepGenM (Token Bool) elemOf :: (Show t, Lift t, Valuable t, Eq t, TokenableTo t a, TokenableTo [t] b, WitnessFor w t) => w -> a -> b -> DepGenM (Token Bool)
elemOf witness a b = runFunction (ElemOf witness) =<< toTupleToken a b elemOf witness a b = runFunction (ElemOf witness) =<< toTupleToken a b
elemOfString :: (TokenableTo String a, TokenableTo [String] b) => a -> b -> DepGenM (Token Bool) elemOf' :: (Show t, Lift t, Valuable t, Eq t, WitnessFor w t, TokenableTo t a, TokenableTo [t] b) => a -> b -> DepGenM (Token Bool)
elemOfString = elemOf StringType elemOf' = elemOf witnessValue
data MakeTemplate = MakeTemplate deriving (Show, Lift) data MakeTemplate = MakeTemplate deriving (Show, Lift)

View File

@ -17,7 +17,7 @@ copyTo path targetDir = do
hasExtension :: (TokenableTo [String] a, TokenableTo FilePath b) => a -> b -> DepGenM (Token Bool) hasExtension :: (TokenableTo [String] a, TokenableTo FilePath b) => a -> b -> DepGenM (Token Bool)
hasExtension exts filename = do hasExtension exts filename = do
ext <- lowerString =<< untupleSndDepGenM =<< fileComponents filename ext <- lowerString =<< untupleSndDepGenM =<< fileComponents filename
ext `elemOfString` exts ext `elemOf'` exts
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM () handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM ()
handleRecipeDir outputDir htmlTemplate indexName dir = do handleRecipeDir outputDir htmlTemplate indexName dir = do