From 206124c1ca7cd1280249fbdcf21153a9622a95df Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sun, 6 Oct 2024 16:28:22 +0200 Subject: [PATCH] Expose general behavior as elemOf --- byg/src/Function.hs | 11 +++-------- byg/src/SiteGenerator.hs | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/byg/src/Function.hs b/byg/src/Function.hs index 640e580..2ed2cc4 100644 --- a/byg/src/Function.hs +++ b/byg/src/Function.hs @@ -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) diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index 1d55520..7fda704 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/src/SiteGenerator.hs @@ -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