generics - Data.Data -- producing dataCast1 for an arity 2 type constructor (partially specialized) -
so data.map has datacast2
defined, makes sense, has arity 2 type constructor. datacast1
defaults const nothing
. datacast2
defined gcast2
.
for reference:
class typeable => data datacast1 :: typeable1 t => (forall d. data d => c (t d)) -> maybe (c a) datacast2 :: typeable2 t => (forall d e. (data d, data e) => c (t d e)) -> maybe (c a) ... gcast1 :: (typeable1 t, typeable1 t') => c (t a) -> maybe (c (t' a)) gcast2 :: (typeable2 t, typeable2 t') => c (t b) -> maybe (c (t' b))
the question @ hand this: given in data.data
, data.typeable
, etc., , given arity 2 type constructor datacast2
defined (say, map
, or (,)
), possible write version of datacast1
right thing partial specialization of type constructor, either 1 specific constructor @ time, or in general?
intuitively, think there should solution, first few tries crashed , burned.
i'm not sure if want, might steer in right direction if it's not. written in similar style gcast
, gcast1
, , gcast2
functions in data.typeable library. more details, "read source, luke".
mydatacast1 :: forall c t d e a.(typeable d, typeable e) => c (t d a) -> maybe (c (t e a)) mydatacast1 x = r r = case typeof (getarg x) == typeof (getarg (fromjust r)) of true -> $ unsafecoerce x false -> nothing getarg :: c (t x a) -> x getarg = undefined
using function can, instance write foo
foo :: typeable d => c (d, a) -> maybe (c (int, a)) foo = mydatacast1
Comments
Post a Comment