Logs: liberachat/#haskell
| 2026-03-09 17:39:27 | <tccq> | possibly, not sure I understand the difference |
| 2026-03-09 17:39:29 | <mauke> | or maybe Reader |
| 2026-03-09 17:39:56 | <EvanR> | an ST program can create mutable variables and arrays for use within its scope |
| 2026-03-09 17:40:07 | <EvanR> | State only has 1 "mutable" variable |
| 2026-03-09 17:40:13 | <EvanR> | accessed using get and put |
| 2026-03-09 17:40:23 | <[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 17:40:32 | <mauke> | Reader is roughly equivalent to function arguments: it takes care of passing a "context value" around |
| 2026-03-09 17:41:01 | <mauke> | State emulates a single mutable value (by secretly taking an extra argument and returning an extra value, the "updated" value) |
| 2026-03-09 17:41:47 | <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 17:41:58 | → | tzh joins (~tzh@c-76-115-131-146.hsd1.or.comcast.net) |
| 2026-03-09 17:42:04 | <EvanR> | just give me a tall State and a do notation to steer her by |
| 2026-03-09 17:42:19 | <mauke> | ST is meant for situations where you want to use imperative features internally, but your public interface is still pure |
| 2026-03-09 17:42:46 | <[exa]> | tccq: ...so I guess: type MemM s a = StateT (RegInfo, STArray s Int Slot) (St s) a |
| 2026-03-09 17:43:07 | <tccq> | yea ok so the other question is which order to layer them in |
| 2026-03-09 17:43:07 | <[exa]> | might be faster as ReaderT if you can store RegInfo behind some kind of ST reference (TVar ?) |
| 2026-03-09 17:43:13 | <tccq> | I think normally I want to update both most of the time |
| 2026-03-09 17:43:17 | <tccq> | so maybe it doesn't matter? |
| 2026-03-09 17:43:51 | <[exa]> | yeah if you want the _values_ in State, you don't need `ST` btw |
| 2026-03-09 17:43:54 | <tccq> | cause the STArray also takes a monad to sequence with right? and that could be my State RegInfo |
| 2026-03-09 17:44:19 | <EvanR> | no STArray does not |
| 2026-03-09 17:44:31 | <[exa]> | the above keeps references in Reader, where you only use the references for mutation, and don't modify the state |
| 2026-03-09 17:44:49 | <EvanR> | having an STArray in a State doesn't sound right at all |
| 2026-03-09 17:45:56 | <[exa]> | tccq: for comparison, did you work with mutable vectors? |
| 2026-03-09 17:46:28 | <tccq> | nope. I've done stuff w/ StateT and ReaderT (a while ago), but never really touched vectors or arrays in haskell |
| 2026-03-09 17:47:12 | <[exa]> | tccq: see https://hackage-content.haskell.org/package/vector-0.13.2.0/docs/Data-Vector-Mutable.html -- they are also parametrized by the `s` |
| 2026-03-09 17:47:47 | <[exa]> | tccq: but the 's' doesn't hold anything and actually cannot, because it's used internally for the state serialization (see the PrimMonad m constraints) |
| 2026-03-09 17:47:57 | <[exa]> | s/state/imperative computations/ |
| 2026-03-09 17:48:51 | <EvanR> | so you want to update a mutable array, let me first introduce you to some category theory |
| 2026-03-09 17:48:57 | <[exa]> | tccq: and with that single `s`, you can allocate and deallocate (and read&write) as many vectors/arrays as you like. The only thing they have in common is that their operations depend on each other (to assert order) via something that the `s` becomes. |
| 2026-03-09 17:49:48 | <tccq> | alright, think I've got it by the right end now, thank you |
| 2026-03-09 17:50:12 | <tccq> | the worst part is the the category theory isn't even that bad, it's the applications that are the hardest to parse ime |
| 2026-03-09 17:50:23 | <tccq> | but practice makes perfect I suppose |
| 2026-03-09 17:50:27 | <[exa]> | tccq: so then you have a bit of a choice of whether store stateful stuff in actual State, or have it "allocated aside" as a side effect, using e.g. the mutable vectors or STArrays, or e.g. TVar |
| 2026-03-09 17:50:44 | <EvanR> | I find vector is a good default when reaching for arrays |
| 2026-03-09 17:51:36 | <mauke> | stateful immutable arrays kind of suck because there are no partial updates. you can only rewrite the whole array |
| 2026-03-09 17:51:56 | <mauke> | so if you're dealing with array updates, State is not a good fit |
| 2026-03-09 17:52:18 | <[exa]> | ..is there a TVar that can be easily run in `ST s` ? |
| 2026-03-09 17:52:32 | <tccq> | I was only looking into STArrays because they seem relatively builtin |
| 2026-03-09 17:52:39 | <tccq> | though that line is never quite clear to me in haskell |
| 2026-03-09 17:53:05 | <[exa]> | tccq: builtin primitives might be tough :) |
| 2026-03-09 17:53:24 | <[exa]> | tbh I'd really recommend going with a mutable vector, it's a very friendly for first tries |
| 2026-03-09 17:53:42 | <[exa]> | *a very friendly choice |
| 2026-03-09 17:53:57 | <mauke> | [exa]: does that even make sense? how would you get a multi-threaded ST? |
| 2026-03-09 17:54:02 | <tccq> | I'll take a look through vector |
| 2026-03-09 17:54:32 | <tccq> | builtin meaning standard library, not necessarily VoidTM### or whatever goes on internally |
| 2026-03-09 17:54:55 | <tccq> | any the vague restriction of it would be cool to have it work with microhs too :) |
| 2026-03-09 17:54:58 | × | chele quits (~chele@user/chele) (Remote host closed the connection) |
| 2026-03-09 17:55:01 | <tccq> | s/any/and |
| 2026-03-09 17:56:19 | <EvanR> | lol TVar. Here I was thinking it would be bad form to bring up STM in a discussion about the confusion between ST and State |
| 2026-03-09 17:58:34 | → | CiaoSen joins (~Jura@2a02:8071:64e1:da0:5a47:caff:fe78:33db) |
| 2026-03-09 17:59:29 | <mauke> | yeah, love those names |
| 2026-03-09 18:00:26 | → | Square joins (~Square@user/square) |
| 2026-03-09 18:00:27 | <mauke> | State: mutable state (emulated). STM: software transactional memory (for safe state in multi-threaded code). ST: state threads (not related to State or threads) |
| 2026-03-09 18:02:40 | × | Square2 quits (~Square4@user/square) (Ping timeout: 245 seconds) |
| 2026-03-09 18:03:23 | → | wootehfoot joins (~wootehfoo@user/wootehfoot) |
| 2026-03-09 18:04:54 | → | wickedjargon joins (~user@S0106f89e28d5699a.vc.shawcable.net) |
| 2026-03-09 18:08:06 | <EvanR> | Data.Array is its own package now and not included in base? |
| 2026-03-09 18:08:17 | <EvanR> | or it always was |
| 2026-03-09 18:19:15 | → | euphores joins (~SASL_euph@user/euphores) |
| 2026-03-09 18:25:49 | <monochrom> | On my CV: "I know C/C++, J/Java/Javascript, ST/STM". >:) |
| 2026-03-09 18:26:43 | <monochrom> | yikes I should have "improved" that to "ST/STM/StateT/" too |
| 2026-03-09 18:42:26 | × | machinedgod quits (~machinedg@d172-219-48-230.abhsia.telus.net) (Ping timeout: 248 seconds) |
| 2026-03-09 18:51:58 | × | DetourNetworkUK quits (~DetourNet@user/DetourNetworkUK) (Read error: Connection reset by peer) |
| 2026-03-09 18:52:22 | → | DetourNetworkUK joins (~DetourNet@user/DetourNetworkUK) |
| 2026-03-09 18:52:40 | → | Everything joins (~Everythin@172-232-54-192.ip.linodeusercontent.com) |
| 2026-03-09 19:10:45 | <__monty__> | Forgot C-- as well. |
| 2026-03-09 19:11:22 | <monochrom> | I am not familiar enough with C--. |
| 2026-03-09 19:11:59 | <monochrom> | But I should be putting "C/C++/C#" there. :) |
| 2026-03-09 19:25:24 | × | Googulator quits (~Googulato@2a01-036d-0106-0119-01e8-0aed-2fac-7c8a.pool6.digikabel.hu) (Quit: Client closed) |
| 2026-03-09 19:25:41 | → | Googulator joins (~Googulato@2a01-036d-0106-0119-01e8-0aed-2fac-7c8a.pool6.digikabel.hu) |
| 2026-03-09 19:25:49 | <Rembane> | monochrom: Has your CV turned into a prefix tree? |
| 2026-03-09 19:25:58 | ← | Everything parts (~Everythin@172-232-54-192.ip.linodeusercontent.com) () |
| 2026-03-09 19:26:19 | → | arandombit joins (~arandombi@2a02:2455:8656:7100:2149:c35e:cd23:4e9a) |
| 2026-03-09 19:26:19 | × | arandombit quits (~arandombi@2a02:2455:8656:7100:2149:c35e:cd23:4e9a) (Changing host) |
| 2026-03-09 19:26:19 | → | arandombit joins (~arandombi@user/arandombit) |
| 2026-03-09 19:26:29 | <monochrom> | haha |
| 2026-03-09 19:26:52 | → | karenw_ joins (~karenw@user/karenw) |
| 2026-03-09 19:26:57 | <monochrom> | Theorem: Every CV is a forest of prefix trees. >:) |
| 2026-03-09 19:27:18 | <Rembane> | I should start my CV with that theorem. :D |
| 2026-03-09 19:29:16 | × | igemnace quits (~igemnace@user/igemnace) (Quit: ZNC 1.9.0+deb2build3 - https://znc.in) |
| 2026-03-09 19:30:10 | → | igemnace joins (~igemnace@user/igemnace) |
| 2026-03-09 19:30:28 | <mauke> | https://github.com/Perl/perl5/blob/3ed2439bc15f60b2ab82a0f91b568a32f9c8bd7d/perl.h#L3203 |
| 2026-03-09 19:33:42 | <EvanR> | including C-- and C++ would be optimized away to nothing |
| 2026-03-09 19:35:58 | <monochrom> | heh |
| 2026-03-09 19:41:04 | <Rembane> | <<anti particle noises intensifies>> |
| 2026-03-09 19:49:21 | × | redshuffle quits (~quassel@45.43.70.75) (Remote host closed the connection) |
| 2026-03-09 19:49:28 | → | redshuffle joins (~quassel@45.43.70.75) |
| 2026-03-09 19:49:45 | × | Lord_of_Life quits (~Lord@user/lord-of-life/x-2819915) (Ping timeout: 245 seconds) |
| 2026-03-09 19:51:05 | × | oskarw quits (~user@user/oskarw) (Remote host closed the connection) |
| 2026-03-09 19:53:29 | → | Lord_of_Life joins (~Lord@user/lord-of-life/x-2819915) |
| 2026-03-09 20:15:03 | → | humasect joins (~humasect@dyn-192-249-132-90.nexicom.net) |
| 2026-03-09 20:26:23 | → | stackdroid18 joins (~stackdroi@user/stackdroid) |
| 2026-03-09 20:29:55 | → | merijn joins (~merijn@host-cl.cgnat-g.v4.dfn.nl) |
| 2026-03-09 20:32:05 | → | prdak joins (~Thunderbi@user/prdak) |
| 2026-03-09 20:36:36 | × | merijn quits (~merijn@host-cl.cgnat-g.v4.dfn.nl) (Ping timeout: 255 seconds) |
| 2026-03-09 20:37:10 | <haskellbridge> | <Zemyla> https://kf8nh.com/_heisenbridge/media/matrix.org/ecaDIhWASUiqwslBshXLptUU/3mmWxB2OSxU/1000008748.jpg |
| 2026-03-09 20:38:23 | × | prdak quits (~Thunderbi@user/prdak) (Ping timeout: 252 seconds) |
| 2026-03-09 20:38:40 | <EvanR> | lol |
| 2026-03-09 20:39:54 | → | prdak joins (~Thunderbi@user/prdak) |
| 2026-03-09 20:40:06 | ← | stackdroid18 parts (~stackdroi@user/stackdroid) () |
All times are in UTC.