-- | Reimplementation of Dynamic that supports dynBind---- We don't have access to the internal representation of Dynamic, otherwise-- we would not have to redefine it completely. Note that we use this only-- internally, so the incompatibility with "our" Dynamic from the standard -- Dynamic is not important.{-# LANGUAGE MagicHash #-}moduleControl.Distributed.Process.Internal.Dynamic(Dynamic(..),toDyn,fromDyn,fromDynamic,dynTypeRep,dynApply,dynApp,dynBind,dynBind',dynKleisli,GHC.unsafeCoerce#)whereimportData.Typeable(Typeable,TypeRep,typeOf,funResultTy,TyCon,splitTyConApp,mkFunTy)importData.Typeable.Internal(funTc)importqualifiedGHC.PrimasGHC(Any,unsafeCoerce#)importData.Maybe(fromMaybe)dataDynamic=DynamicTypeRepGHC.AnyderivingTypeabletoDyn::Typeablea=>a->DynamictoDynx=Dynamic(typeOfx)(GHC.unsafeCoerce#x)fromDyn::Typeablea=>Dynamic->a->afromDyn(Dynamicrepval)a=ifrep==typeOfathenGHC.unsafeCoerce#valelseafromDynamic::foralla.Typeablea=>Dynamic->MaybeafromDynamic(Dynamicrepval)=ifrep==typeOf(undefined::a)thenJust(GHC.unsafeCoerce#val)elseNothingdynTypeRep::Dynamic->TypeRepdynTypeRep(Dynamict_)=tinstanceShowDynamicwhereshow=show.dynTypeRepdynApply::Dynamic->Dynamic->MaybeDynamicdynApply(Dynamict1f)(Dynamict2x)=casefunResultTyt1t2ofJustt3->Just(Dynamict3(GHC.unsafeCoerce#fx))Nothing->NothingdynApp::Dynamic->Dynamic->DynamicdynAppfx=fromMaybe(errortypeError)(dynApplyfx)wheretypeError="Type error in dynamic application.\n"++"Can't apply function "++showf++" to argument "++showxdynBind::TyCon->(forallab.ma->(a->mb)->mb)->Dynamic->Dynamic->MaybeDynamicdynBindmbind(Dynamict1x)(Dynamict2f)=casesplitTyConAppt1of(m',[a])|m'==m->casefunResultTyt2aofJustmb->Just(Dynamicmb(GHC.unsafeCoerce#bindxf))_->Nothing_->NothingdynBind'::TyCon->(forallab.ma->(a->mb)->mb)->Dynamic->Dynamic->DynamicdynBind'mbindxf=fromMaybe(errortypeError)(dynBindmbindxf)wheretypeError="Type error in dynamic bind.\nCan't bind "++showx++" to "++showf-- | Dynamically typed Kleisli compositiondynKleisli::TyCon->(forallabc.(a->mb)->(b->mc)->a->mc)->Dynamic->Dynamic->MaybeDynamicdynKleislimcomp(Dynamictff)(Dynamictgg)=casesplitTyConApptfof(arr1,[a,mb])|arr1==funTc->casesplitTyConApptgof(arr2,[b,mc])|arr2==funTc->casesplitTyConAppmbof(m',[b'])|m'==m&&b'==b->casesplitTyConAppmcof(m'',[_c])|m''==m->Just(Dynamic(mkFunTyamc)(GHC.unsafeCoerce#compfg))_->Nothing_->Nothing_->Nothing_->Nothing