Use Typeable instead of homegrown WitnessFor for ElemOf

This commit is contained in:
Niels G. W. Serup 2024-10-09 23:19:32 +02:00
parent 418ebcb60f
commit 5af98f6c9a
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
1 changed files with 5 additions and 4 deletions

View File

@ -16,11 +16,12 @@ module Function
import Prelude hiding (String, FilePath)
import Types.Values
import Types.Value (Valuable, WitnessFor(..))
import Types.Value (Valuable)
import Types.Function
import Types.Token (Token(..))
import DependencyGenerator (DepGenM, TokenableTo(..), toTupleToken, runFunction)
import Type.Reflection (Typeable, TypeRep, typeRep)
import qualified Codec.Picture as CP
import qualified Codec.Picture.STBIR as CPS
import Data.Char (toLower)
@ -76,13 +77,13 @@ lowerString :: TokenableTo String a => a -> DepGenM (Token String)
lowerString a = runFunction LowerString =<< toToken a
data ElemOf a where ElemOf :: WitnessFor w a => w -> ElemOf a
data ElemOf a where ElemOf :: TypeRep a -> ElemOf a
deriving instance Show (ElemOf a)
instance (Show a, Valuable a, Eq a) => IsFunction (ElemOf a) (a, [a]) Bool where
evalFunction (ElemOf _) (y, ys) = y `elem` ys
elemOf :: forall t w a b. (Show 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
elemOf :: forall t a b. (Show t, Valuable t, Eq t, TokenableTo t a, TokenableTo [t] b, Typeable t) => a -> b -> DepGenM (Token Bool)
elemOf a b = runFunction (ElemOf (typeRep :: TypeRep t)) =<< toTupleToken a b
data MakeTemplate = MakeTemplate deriving Show