From 347cc07c93c3d90bc23f531874835518b42c7fc7 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sun, 6 Oct 2024 16:04:22 +0200 Subject: [PATCH] Begin generalizing elemOf --- byg/src/Function.hs | 15 ++++++++++----- byg/src/SiteGenerator.hs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/byg/src/Function.hs b/byg/src/Function.hs index bd22d26..14e79db 100644 --- a/byg/src/Function.hs +++ b/byg/src/Function.hs @@ -5,6 +5,7 @@ module Function , fileComponents , lowerString , elemOf + , elemOfString , makeTemplate , applyTemplate , toText @@ -15,6 +16,7 @@ module Function import Prelude hiding (String, FilePath) import Types.Values +import Types.Value (Valuable) import Types.Function import Types.Token (Token(..)) import DependencyGenerator (DepGenM, TokenableTo(..), toTupleToken, runFunction) @@ -75,12 +77,15 @@ lowerString :: TokenableTo String a => a -> DepGenM (Token String) lowerString a = runFunction LowerString =<< toToken a -data ElemOf = ElemOf deriving (Show, Lift) -instance IsFunction ElemOf (String, [String]) Bool where - evalFunction ElemOf (y, ys) = y `elem` ys +data ElemOf a = ElemOf a deriving (Show, Lift) +instance (Show a, Lift a, Valuable a, Eq a) => IsFunction (ElemOf a) (a, [a]) Bool where + evalFunction (ElemOf _) (y, ys) = y `elem` ys -elemOf :: (TokenableTo String a, TokenableTo [String] b) => a -> b -> DepGenM (Token Bool) -elemOf a b = runFunction ElemOf =<< toTupleToken a b +elemOf :: (Show t, Lift t, Valuable t, Eq t, TokenableTo t a, TokenableTo [t] b) => t -> a -> b -> DepGenM (Token Bool) +elemOf witness a b = runFunction (ElemOf witness) =<< toTupleToken a b + +elemOfString :: (TokenableTo String a, TokenableTo [String] b) => a -> b -> DepGenM (Token Bool) +elemOfString a b = elemOf "" a b data MakeTemplate = MakeTemplate deriving (Show, Lift) diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index 7fda704..6c6f2de 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 `elemOfString` exts handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM () handleRecipeDir outputDir htmlTemplate indexName dir = do