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 , fileComponents
, lowerString , lowerString
, elemOf , elemOf
, elemOf'
, makeTemplate , makeTemplate
, applyTemplate , applyTemplate
, toText , toText
@ -83,8 +82,7 @@ class (Show w, Lift w) => WitnessFor w t | w -> t, t -> w where
witnessValue :: w witnessValue :: w
data StringType = StringType deriving (Show, Lift) data StringType = StringType deriving (Show, Lift)
instance WitnessFor StringType String where instance WitnessFor StringType String where witnessValue = StringType
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)
@ -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 instance (Show a, Lift a, Valuable a, Eq a) => IsFunction (ElemOf a) (a, [a]) Bool where
evalFunction (ElemOf _) (y, ys) = y `elem` ys 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 :: 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 witness a b = runFunction (ElemOf witness) =<< toTupleToken a b elemOf a b = runFunction (ElemOf (witnessValue :: w)) =<< 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
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 `elemOf'` 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