1
0

Use Typeable instead of homegrown WitnessFor for ElemOf

Este cometimento está contido em:
2024-10-09 23:19:32 +02:00
ascendente 418ebcb60f
cometimento 5af98f6c9a

Ver ficheiro

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