[GHC] #13178: Generalize type of runRW#
GHC
ghc-devs at haskell.org
Thu Jan 26 00:06:59 UTC 2017
#13178: Generalize type of runRW#
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: dfeuer
Type: feature request | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3012
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by dfeuer):
Yes. Consider `runST` for ''lazy'' `ST`. We currently have
{{{#!hs
runST :: (forall s. ST s a) -> a
runST st = case st of ST the_st -> let (r,_) = the_st (S# realWorld#) in r
{-# NOINLINE runST #-}
}}}
If we want to switch to `runRW#` using today's `runRW#`, we need to do
something like this:
{{{#!hs
runST (ST st) =
case runRW# (\s -> case st (S# s) of
(r, _s') -> (# s, r #)) of
(# _, r #) -> r
}}}
That is, we need to pack up the result with a state token to satisfy the
type of `runRW#`. Note that we'd use the token we got from `runRW#`
because opening up the one `st` returned would force actions that may not
be necessary. Then once we have the result from `runRW#`, we have to match
on it again to remove the unneeded state token. With the more general
type, we can write this as
{{{#!hs
runST (ST st) = runRW# (\s -> case st (S# s) of (r, _) -> r)
}}}
Much simpler, no?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list