logo       

RE: very strange behavior (crashes!) with Dynamics: msg#00032

lang.haskell.glasgow.bugs

Subject: RE: very strange behavior (crashes!) with Dynamics

When deriving Typeable instead of writing the instances myself, this bug
doesn't pop up. This puts it on a back burner for me, but it's still
something that should probably get fixed :).

--
Hal Daume III | hdaume@xxxxxxx
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume


> -----Original Message-----
> From: glasgow-haskell-bugs-admin@xxxxxxxxxxx
> [mailto:glasgow-haskell-bugs-admin@xxxxxxxxxxx] On Behalf Of Hal Daume
> Sent: Thursday, August 14, 2003 4:47 PM
> To: Hal Daume; glasgow-haskell-bugs@xxxxxxxxxxx
> Subject: RE: very strange behavior (crashes!) with Dynamics
>
>
> Okay, I know I promised that was the last one, but you can
> actually get
> it simpler. Remove all the dynamic map stuff. Just have two files,
> Range.hs and Coref.hs, with:
>
> module Range where
>
> import Data.Dynamic
>
> data Range = Single Int
> | Range Int Int
> deriving (Eq, Ord, Show)
>
> rangeTypeCon = mkTyCon "Range" ; rangeTypeRep = mkAppTy
> rangeTypeCon []
> instance Typeable Range where typeOf _ = rangeTypeRep
> {-# NOINLINE rangeTypeCon #-}
> {-# NOINLINE rangeTypeRep #-}
>
> rangeDShow :: DShow
> rangeDShow = dshowLabel (shows :: Range -> ShowS)
>
> type DShow = Dynamic -> Maybe ShowS
>
> dshowLabel :: Typeable a => (a -> ShowS) -> DShow
> dshowLabel x d =
> case fromDynamic d of
> Nothing -> Nothing
> Just v -> Just (shows (typeOf v) . showChar '=' . x v)
>
>
>
> and
>
>
>
> module Coref where
>
> import Data.Dynamic
> import Range
>
> data Coref = Coref Int Int Bool (Maybe String)
> deriving (Eq, Ord, Show)
>
> corefTypeCon = mkTyCon "Coref" ; corefTypeRep = mkAppTy
> corefTypeCon []
> instance Typeable Coref where typeOf _ = corefTypeRep
> {-# NOINLINE corefTypeCon #-}
> {-# NOINLINE corefTypeRep #-}
>
> corefDShow = dshowLabel (shows :: Coref -> ShowS)
>
>
>
> now load Coref, do 'Monad.liftM ($"") (corefDShow (toDyn
> (Range 1 1)))'
> which works fine (returns Nothing), then touch it and reload it and do
> the same thing and you'll crash.
>
> --
> Hal Daume III | hdaume@xxxxxxx
> "Arrest this man, he talks in maths." | www.isi.edu/~hdaume


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise