[GHC] #13178: Generalize type of runRW#
#13178: Generalize type of runRW# -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Currently, we have {{{#!hs runRW# :: (State# RealWorld -> (# State# RealWorld, o #)) -> (# State# RealWorld, o #) }}} where `o` is open-kinded. This type is a bit annoying, because `runRW#` is very often used in contexts where we want to discard the state token. I think it should be easy to generalize, however: {{{#!hs runRW# :: (State# RealWorld -> o) -> o }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13178: Generalize type of runRW# -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: feature request | Status: new 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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * owner: => dfeuer * differential: => Phab:D3012 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: new => patch -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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 simonpj): Can you give an exmaple of were this is helpful? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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
#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 simonpj): I see. Yes, ok. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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 David Feuer <David.Feuer@…>): In [changeset:"c344005b2344800bee9fee1c5ca97867691b9c70/ghc" c344005b/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c344005b2344800bee9fee1c5ca97867691b9c70" Generalize the type of runRW# * Generalize the type of `runRW#` to allow arbitrary return types. * Use `runRW#` to implement `Control.Monad.ST.Lazy.runST` (this provides evidence that it actually works properly with the generalized type). * Adjust the type signature in the definition of `oneShot` to match the one it is given in `MkId`. Reviewers: simonmar, austin, bgamari, hvr Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3012 GHC Trac Issues: #13178 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13178: Generalize type of runRW# -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | 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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13178#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC