{-# LANGUAGE UndecidableInstances #-} -- | Interpreter to duplicate the representation of an expression -- in order to evaluate it with different interpreters. -- -- NOTE: this is a more verbose, less clear, -- and maybe less efficient alternative -- to maintaining the universal polymorphism of @repr@ at parsing time -- as done with 'Forall_Repr_with_Context'; -- it is mainly here for the sake of curiosity. module Language.Symantic.Interpreting.Dup where import Data.Proxy -- | Interpreter's data. data DupI repr1 repr2 a = DupI { dupI_1 :: repr1 a , dupI_2 :: repr2 a } dupI0 :: (cl r, cl s) => Proxy cl -> (forall repr. cl repr => repr a) -> DupI r s a dupI0 _cl f = f `DupI` f dupI1 :: (cl r, cl s) => Proxy cl -> (forall repr. cl repr => repr a -> repr b) -> DupI r s a -> DupI r s b dupI1 _cl f (a1 `DupI` a2) = f a1 `DupI` f a2 dupI2 :: (cl r, cl s) => Proxy cl -> (forall repr. cl repr => repr a -> repr b -> repr c) -> DupI r s a -> DupI r s b -> DupI r s c dupI2 _cl f (a1 `DupI` a2) (b1 `DupI` b2) = f a1 b1 `DupI` f a2 b2 dupI3 :: (cl r, cl s) => Proxy cl -> (forall repr. cl repr => repr a -> repr b -> repr c -> repr d) -> DupI r s a -> DupI r s b -> DupI r s c -> DupI r s d dupI3 _cl f (a1 `DupI` a2) (b1 `DupI` b2) (c1 `DupI` c2) = f a1 b1 c1 `DupI` f a2 b2 c2