{"action":"created","issue":{"url":"https://api.github.com/repos/purescript/purescript-st/issues/19","repository_url":"https://api.github.com/repos/purescript/purescript-st","labels_url":"https://api.github.com/repos/purescript/purescript-st/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/purescript/purescript-st/issues/19/comments","events_url":"https://api.github.com/repos/purescript/purescript-st/issues/19/events","html_url":"https://github.com/purescript/purescript-st/issues/19","id":318965781,"node_id":"MDU6SXNzdWUzMTg5NjU3ODE=","number":19,"title":"Global region, take two","user":{"login":"rightfold","id":5132125,"node_id":"MDQ6VXNlcjUxMzIxMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/5132125?v=4","gravatar_id":"","url":"https://api.github.com/users/rightfold","html_url":"https://github.com/rightfold","followers_url":"https://api.github.com/users/rightfold/followers","following_url":"https://api.github.com/users/rightfold/following{/other_user}","gists_url":"https://api.github.com/users/rightfold/gists{/gist_id}","starred_url":"https://api.github.com/users/rightfold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rightfold/subscriptions","organizations_url":"https://api.github.com/users/rightfold/orgs","repos_url":"https://api.github.com/users/rightfold/repos","events_url":"https://api.github.com/users/rightfold/events{/privacy}","received_events_url":"https://api.github.com/users/rightfold/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-30T17:13:37Z","updated_at":"2019-01-04T15:44:12Z","closed_at":null,"author_association":"NONE","body":"Previous issue was #7, but that was still about effect rows.\r\n\r\nNow that we no longer use effect rows, it is no longer possible to use ST globally by adding `st :: ST a` to the effect row of `main`.\r\n\r\nI think that we can abstract over Effect and ST so that code that uses mutation can be used on both global and local state, as follows.\r\n\r\n```purescript\r\nforeign import data Global :: Region\r\n\r\neffectToST :: Effect ~> ST Global\r\nstToEffect :: ST Global ~> Effect\r\n\r\ninstance MonadEffect (ST Global) where\r\n  liftEffect = effectToST\r\n```\r\n\r\nNow we can abstract over it.\r\n\r\n```purescript\r\nclass MonadST s m | m -> s where\r\n  liftST :: ST s ~> m\r\n\r\ninstance monadSTEffect :: MonadST Global Effect where\r\n  liftST = stToEffect\r\n\r\ninstance monadSTST :: MonadST s ST where\r\n  liftST = id\r\n```\r\n\r\nNow, `STRef` and `Ref` can be unified, allowing for code reuse. Similar for `STArray` and something I don't think exists yet (useful for fixing https://github.com/purescript-node/purescript-node-process/issues/8).\r\n\r\n```purescript\r\nforeign import data Ref :: Region -> Type -> Type\r\n\r\nnewRef :: forall s m a. MonadST s m => a -> m (Ref s a)\r\nreadRef :: forall s m a. MonadST s m => Ref s a -> m a\r\nwriteRef :: forall s m a. MonadST s m => Ref s a -> a -> m Unit\r\n```\r\n\r\nAdditionally, ST can be used without explicit lifting with monad transformers."},"comment":{"url":"https://api.github.com/repos/purescript/purescript-st/issues/comments/451480268","html_url":"https://github.com/purescript/purescript-st/issues/19#issuecomment-451480268","issue_url":"https://api.github.com/repos/purescript/purescript-st/issues/19","id":451480268,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTQ4MDI2OA==","user":{"login":"eric-corumdigital","id":36901728,"node_id":"MDQ6VXNlcjM2OTAxNzI4","avatar_url":"https://avatars3.githubusercontent.com/u/36901728?v=4","gravatar_id":"","url":"https://api.github.com/users/eric-corumdigital","html_url":"https://github.com/eric-corumdigital","followers_url":"https://api.github.com/users/eric-corumdigital/followers","following_url":"https://api.github.com/users/eric-corumdigital/following{/other_user}","gists_url":"https://api.github.com/users/eric-corumdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-corumdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-corumdigital/subscriptions","organizations_url":"https://api.github.com/users/eric-corumdigital/orgs","repos_url":"https://api.github.com/users/eric-corumdigital/repos","events_url":"https://api.github.com/users/eric-corumdigital/events{/privacy}","received_events_url":"https://api.github.com/users/eric-corumdigital/received_events","type":"User","site_admin":false},"created_at":"2019-01-04T15:44:12Z","updated_at":"2019-01-04T15:44:12Z","author_association":"NONE","body":"Am wanting to use STObject in Effect. Got my upvote."}}
{"actor":{"display_login":"eric-corumdigital"}}