[ ghc-Bugs-439905 ] newtype vs data TC problem

noreply@sourceforge.net noreply@sourceforge.net
Mon, 09 Jul 2001 18:06:17 -0700


Bugs item #439905, was opened at 2001-07-09 18:06
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=439905&group_id=8032

Category: Compiler (Type checker)
Group: 5.00
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: newtype vs data TC problem

Initial Comment:
The following  module stops with TC problems, but if
you replace the newtype with data, things work fine.
This problem is in the HEAD, but not in 5.00

Andy 

module State2 (StateM, runStateM, genUniqM) where

import ST

newtype StateM a = StateM (forall s . STRef s Int -> 
ST s a)

runStateM :: StateM a -> Int -> (a,Int)
runStateM (StateM fn) u = 
   runST (do { uRef <- newSTRef u
             ; res <- fn uRef
             ; u <- readSTRef uRef
	     ; return (res,u)
             })

unStateM :: StateM a -> STRef b Int -> ST b a
unStateM (StateM fn) u = fn u

genUniqM :: StateM Int
genUniqM = StateM (\ uRef -> do { u <- readSTRef uRef
				; writeSTRef uRef (u+1)
				; return u
				})

instance Monad StateM where
  return a = StateM (\ uRef -> return a)
  m >>= k  = StateM (\ uRef -> do { r <- unStateM m 
uRef
                                  ; unStateM (k r) uRef
				  })



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=439905&group_id=8032