[Hugs-users] Re: one more problem with Hugs

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Mar 8 14:25:56 EST 2006


Hello Bulat,

Tuesday, March 7, 2006, 2:57:47 PM, you wrote:

BZ> The following code compiles with GHC but not with Hugs. moreover, if
BZ> you replace STURef with STRef in instance definition, all will be
BZ> fine. bug?

i found the answer himself. Hugs just can't properly understand kind
of STURef in this case. "type STURef = STRef" should be changed to
"type STURef s a = STRef s a". btw, there was also another cases where Hugs
can't determine kind of identifier from such "partial type declarations"

... after checking my solution: Hugs also don't allow to use type
synonym here, so i should change this declaration to
"newtype STURef s a = STURef (STRef s a)". at least this work....


BZ> {-# OPTIONS_GHC -cpp -fglasgow-exts #-}
BZ> import Control.Monad.ST
BZ> import Data.STRef

BZ> --
BZ> -----------------------------------------------------------------------------
BZ> -- Unboxed references in ST monad

BZ> type STURef = STRef

BZ> -- | Create new unboxed reference in ST monad
BZ> newSTURef :: e -> ST s (STURef s e)
BZ> newSTURef = newSTRef

BZ> --
BZ> -----------------------------------------------------------------------------
BZ> -- Monad-neutral interface for fast unboxed references

BZ> class (Monad m) => URef m r | m->r, r->m where
BZ>     newURef   :: a -> m (r a)

BZ> instance URef (ST s) (STURef s) where
BZ>     newURef = newSTURef

BZ> --
BZ> -----------------------------------------------------------------------------
BZ> -- Main

BZ> test = runST ( do newURef (0::Int)
BZ>                   return '1'
BZ>              )

BZ>   




-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Hugs-Users mailing list