From 424a688d15be5c3d980774f3ca2b2667d0c01bf0 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sun, 6 Oct 2024 16:11:54 +0200 Subject: [PATCH] Play with witnesses, kind of --- byg/src/Function.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/byg/src/Function.hs b/byg/src/Function.hs index 14e79db..5d2b208 100644 --- a/byg/src/Function.hs +++ b/byg/src/Function.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FunctionalDependencies #-} module Function ( concatStrings , concatTexts @@ -77,15 +78,22 @@ lowerString :: TokenableTo String a => a -> DepGenM (Token String) lowerString a = runFunction LowerString =<< toToken a +class WitnessFor w t | w -> t where + emptyValue :: w -> t + +data StringType = StringType +instance WitnessFor StringType String where + emptyValue StringType = "" + 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 :: (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 +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 (emptyValue witness)) =<< toTupleToken a b elemOfString :: (TokenableTo String a, TokenableTo [String] b) => a -> b -> DepGenM (Token Bool) -elemOfString a b = elemOf "" a b +elemOfString = elemOf StringType data MakeTemplate = MakeTemplate deriving (Show, Lift)