Expose general behavior as elemOf

This commit is contained in:
Niels G. W. Serup 2024-10-06 16:28:22 +02:00
parent 43f2cef419
commit 206124c1ca
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
2 changed files with 4 additions and 9 deletions

View File

@ -7,7 +7,6 @@ module Function
, fileComponents
, lowerString
, elemOf
, elemOf'
, makeTemplate
, applyTemplate
, toText
@ -83,8 +82,7 @@ class (Show w, Lift w) => WitnessFor w t | w -> t, t -> w where
witnessValue :: w
data StringType = StringType deriving (Show, Lift)
instance WitnessFor StringType String where
witnessValue = StringType
instance WitnessFor StringType String where witnessValue = StringType
data ElemOf a where ElemOf :: WitnessFor w a => w -> ElemOf a
deriving instance Show (ElemOf a)
@ -92,11 +90,8 @@ deriving instance Lift (ElemOf a)
instance (Show a, Lift a, Valuable a, Eq a) => IsFunction (ElemOf a) (a, [a]) Bool where
evalFunction (ElemOf _) (y, ys) = y `elem` ys
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' :: (Show t, Lift t, Valuable t, Eq t, WitnessFor w t, TokenableTo t a, TokenableTo [t] b) => a -> b -> DepGenM (Token Bool)
elemOf' = elemOf witnessValue
elemOf :: forall t w a b. (Show t, Lift t, Valuable t, Eq t, TokenableTo t a, TokenableTo [t] b, WitnessFor w t) => a -> b -> DepGenM (Token Bool)
elemOf a b = runFunction (ElemOf (witnessValue :: w)) =<< toTupleToken a b
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 exts filename = do
ext <- lowerString =<< untupleSndDepGenM =<< fileComponents filename
ext `elemOf'` exts
ext `elemOf` exts
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM ()
handleRecipeDir outputDir htmlTemplate indexName dir = do