very strange behavior (crashes!) with Dynamics

Hal Daume t-hald at microsoft.com
Fri Aug 15 11:55:13 EDT 2003


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 at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume


> -----Original Message-----
> From: glasgow-haskell-bugs-admin at haskell.org 
> [mailto:glasgow-haskell-bugs-admin at haskell.org] On Behalf Of Hal Daume
> Sent: Thursday, August 14, 2003 4:47 PM
> To: Hal Daume; glasgow-haskell-bugs at haskell.org
> 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 at isi.edu
>  "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume



More information about the Glasgow-haskell-bugs mailing list