2026/03/09

Newest at the top

2026-03-09 18:45:56 +0100 <[exa]> tccq: for comparison, did you work with mutable vectors?
2026-03-09 18:44:49 +0100 <EvanR> having an STArray in a State doesn't sound right at all
2026-03-09 18:44:31 +0100 <[exa]> the above keeps references in Reader, where you only use the references for mutation, and don't modify the state
2026-03-09 18:44:19 +0100 <EvanR> no STArray does not
2026-03-09 18:43:54 +0100 <tccq> cause the STArray also takes a monad to sequence with right? and that could be my State RegInfo
2026-03-09 18:43:51 +0100 <[exa]> yeah if you want the _values_ in State, you don't need `ST` btw
2026-03-09 18:43:17 +0100 <tccq> so maybe it doesn't matter?
2026-03-09 18:43:13 +0100 <tccq> I think normally I want to update both most of the time
2026-03-09 18:43:07 +0100 <[exa]> might be faster as ReaderT if you can store RegInfo behind some kind of ST reference (TVar ?)
2026-03-09 18:43:07 +0100 <tccq> yea ok so the other question is which order to layer them in
2026-03-09 18:42:46 +0100 <[exa]> tccq: ...so I guess: type MemM s a = StateT (RegInfo, STArray s Int Slot) (St s) a
2026-03-09 18:42:19 +0100 <mauke> ST is meant for situations where you want to use imperative features internally, but your public interface is still pure
2026-03-09 18:42:04 +0100 <EvanR> just give me a tall State and a do notation to steer her by
2026-03-09 18:41:58 +0100tzh(~tzh@c-76-115-131-146.hsd1.or.comcast.net) tzh
2026-03-09 18:41:47 +0100 <mauke> ST is an execution environment that provides genuine mutable variables (and arrays), which you can allocate/read/write within the ST context. the catch is that all variables are "local": you must return a pure result
2026-03-09 18:41:01 +0100 <mauke> State emulates a single mutable value (by secretly taking an extra argument and returning an extra value, the "updated" value)
2026-03-09 18:40:32 +0100 <mauke> Reader is roughly equivalent to function arguments: it takes care of passing a "context value" around
2026-03-09 18:40:23 +0100 <[exa]> tccq: the point is that the type `s` there only serves the ordering of operations. Your array is indexed by the `s` for (among other) the purpose that it's hard to get it out of the execution of runST that uses some concrete `s` (that you don't know)
2026-03-09 18:40:13 +0100 <EvanR> accessed using get and put
2026-03-09 18:40:07 +0100 <EvanR> State only has 1 "mutable" variable
2026-03-09 18:39:56 +0100 <EvanR> an ST program can create mutable variables and arrays for use within its scope
2026-03-09 18:39:29 +0100 <mauke> or maybe Reader
2026-03-09 18:39:27 +0100 <tccq> possibly, not sure I understand the difference
2026-03-09 18:39:27 +0100 <[exa]> yes, State or Reader (ok for mutables) over the ST
2026-03-09 18:39:15 +0100 <mauke> that sounds more like State, not ST
2026-03-09 18:38:53 +0100 <tccq> but I don't want to do that and hint to the compiler that there is only ever one array
2026-03-09 18:38:39 +0100 <[exa]> tccq: in short, you don't need to carry these in the type -- you make arrays like you would with mutable vectors in IO. These are "carried through" but only implicitly.
2026-03-09 18:38:38 +0100 <tccq> I could write all of this by passing an array and this record to every function
2026-03-09 18:38:09 +0100 <tccq> eys
2026-03-09 18:38:05 +0100 <[exa]> tccq: ahh so reginfo is the actual state that you want to hold, together with the array
2026-03-09 18:37:50 +0100 <mauke> the "state" is not your data
2026-03-09 18:37:38 +0100 <mauke> never
2026-03-09 18:37:35 +0100 <mauke> no
2026-03-09 18:37:29 +0100 <tccq> I understand s is scoped so that the state can't escape, but I want to use it at some specific type right?
2026-03-09 18:36:41 +0100 <tccq> like I said I'm trying to make a little stack machine
2026-03-09 18:36:33 +0100 <tccq> RegInfo is just a big record if ints and stuff
2026-03-09 18:36:10 +0100 <lambdabot> Variable not in scope: runSTArray
2026-03-09 18:36:10 +0100 <lambdabot> error: [GHC-88464]
2026-03-09 18:36:09 +0100 <[exa]> tccq: (not sure what RegInfo is)
2026-03-09 18:36:09 +0100 <mauke> :t runSTArray
2026-03-09 18:35:46 +0100 <mauke> ^ this fella does
2026-03-09 18:35:42 +0100 <[exa]> tccq: more like `type MemM s a = STArray s Int Slot`
2026-03-09 18:35:42 +0100 <lambdabot> (forall s. ST s a) -> a
2026-03-09 18:35:41 +0100 <mauke> :t runST
2026-03-09 18:35:39 +0100 <mauke> you don't get to choose an s
2026-03-09 18:34:51 +0100 <mauke> that doesn't look like s
2026-03-09 18:34:16 +0100 <[exa]> tccq: the "state" there is more of a token that doesn't really carry anything
2026-03-09 18:34:09 +0100 <tccq> use get/put for RegInfo and read/writeArray for the array?
2026-03-09 18:33:53 +0100 <tccq> something like `type MemM a = (STArray RegInfo) Int Slot (ST RegInfo) a`?
2026-03-09 18:32:36 +0100 <mauke> no, you can use the same s for both