Newest at the top
2025-01-31 01:50:58 +0100 | <dminuoso> | euouae: This is an alternate description of (>>=), and it perhaps visualizes nicely that there's a sort of composition idea going on. |
2025-01-31 01:50:03 +0100 | <yahb2> | join :: Monad m => m (m a) -> m a |
2025-01-31 01:50:03 +0100 | <dminuoso> | % :t join |
2025-01-31 01:50:01 +0100 | <yahb2> | <no output> |
2025-01-31 01:50:01 +0100 | <dminuoso> | % import Control.Monad |
2025-01-31 01:49:55 +0100 | <yahb2> | <interactive>:1:1: error: [GHC-88464] Variable not in scope: join |
2025-01-31 01:49:55 +0100 | <dminuoso> | % :t join |
2025-01-31 01:49:18 +0100 | <dminuoso> | Just keep that thought mind for the future |
2025-01-31 01:48:53 +0100 | <dminuoso> | euouae: One last thing: That "funky composition" you talked about, that's where the monad lies. :-) |
2025-01-31 01:48:52 +0100 | mange | (~user@user/mange) mange |
2025-01-31 01:46:30 +0100 | monochrm | monochrom |
2025-01-31 01:46:29 +0100 | monochrom | (trebla@216.138.220.146) (Ping timeout: 260 seconds) |
2025-01-31 01:46:00 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 252 seconds) |
2025-01-31 01:45:55 +0100 | <euouae> | But your example is very helpful, to keep in mind pure computation / IO stuff inside parsing |
2025-01-31 01:45:40 +0100 | <euouae> | I think my composable state machine intuition is running into trouble with StateT. Transformers seem like a different beast, I'll have to think about it more. |
2025-01-31 01:45:16 +0100 | monochrm | (trebla@216.138.220.146) |
2025-01-31 01:44:32 +0100 | <euouae> | I'm going to assume that it'll leak out the details of try |
2025-01-31 01:44:15 +0100 | <euouae> | right |
2025-01-31 01:43:29 +0100 | <dminuoso> | (Assuming you use `try` of course) |
2025-01-31 01:43:15 +0100 | <dminuoso> | You can also use `ParsecT e s IO`, then you can suddenly do `liftIO (putStrLn "Hello world")` in the middle of your parser. Note, that because megaparsec will do backtracking this will have some interesting/strange behavior... which is non-determinism in fact. |
2025-01-31 01:42:13 +0100 | <dminuoso> | type Parsec e s = ParsecT e s Identity |
2025-01-31 01:42:06 +0100 | <dminuoso> | https://hackage.haskell.org/package/megaparsec-9.7.0/docs/Text-Megaparsec.html#t:Parsec |
2025-01-31 01:41:46 +0100 | <dminuoso> | If you dont want IO, you can just layer it over `Identity`, which is sort of the "does nothing monad", giving you just the parsing effects. |
2025-01-31 01:41:25 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) merijn |
2025-01-31 01:41:14 +0100 | <dminuoso> | The reason you can do this, is because all this parsing effect is in a transformer ParsecT which you can layer over any other monad. |
2025-01-31 01:40:55 +0100 | <dminuoso> | If you use it together with IO, you can interleave your parser with IO - say print statements or database calls |
2025-01-31 01:40:29 +0100 | <dminuoso> | euouae: Your megaparsec parser can run either in pure mode, or it can run together with IO. |
2025-01-31 01:40:04 +0100 | <dminuoso> | euouae: Lets pick a more concrete examplee: |
2025-01-31 01:39:17 +0100 | <dminuoso> | ANd you can layer it over IO to have state, non-determinism, exceptions and real world nuclear missile effects. |
2025-01-31 01:39:00 +0100 | <dminuoso> | And if you add ListT (which adds non-determinism), you could have non-determinism, state and exceptions |
2025-01-31 01:38:35 +0100 | <dminuoso> | Them being transformers means you can layer them ontop of each other, giving you a Monad that has both state *and* exceptions. |
2025-01-31 01:38:33 +0100 | <geekosaur> | so, StateT doesn't just model state; it adds state to something. It transforms something else by adding state to it |
2025-01-31 01:38:20 +0100 | <dminuoso> | euouae: StateT allows you to drag some state around, while ExceptT allows you to throw exceptions. |
2025-01-31 01:37:55 +0100 | <dminuoso> | THat may or may not make any sense to you. |
2025-01-31 01:37:53 +0100 | <euouae> | With a State I know I have a 'state processor' and an 'output value' but what is the transformer for? |
2025-01-31 01:37:49 +0100 | <dminuoso> | euouae: If we think of Monads not as "state" but as some generalized idea of effects, then transformers lets us combine different effects. |
2025-01-31 01:37:24 +0100 | <euouae> | but what is transformer? |
2025-01-31 01:37:19 +0100 | <euouae> | yup. thank you |
2025-01-31 01:37:03 +0100 | <dminuoso> | euouae: Anyhow. Do try to build the state intuition around `>>=` and `pure` - and then test it in the future. |
2025-01-31 01:36:12 +0100 | <dminuoso> | Just like we teach newtonian physics in school, despite general relativity being more accurate. |
2025-01-31 01:35:44 +0100 | <dminuoso> | euouae: I dont want discredit this particular intuition, because I think it *is* a good starting point |
2025-01-31 01:35:25 +0100 | <hololeap> | IO being (State RealWorld a) is more of a mental model |
2025-01-31 01:35:22 +0100 | <dminuoso> | Or you would need to do some more gymnastics. |
2025-01-31 01:35:03 +0100 | <dminuoso> | euouae: There's a bunch of things you can do in IO that... isnt quite about changing the real world. |
2025-01-31 01:34:55 +0100 | <euouae> | Is IO not a state |
2025-01-31 01:34:34 +0100 | <euouae> | I'm not sure what you mean by proving it wrong |
2025-01-31 01:34:33 +0100 | <hololeap> | I can't remember how to do 'unmtl' in #haskell |
2025-01-31 01:33:43 +0100 | <dminuoso> | Given that you could just `launchMissiles` and change the state of the real world with IO. |
2025-01-31 01:33:18 +0100 | <dminuoso> | euouae: And perhaps, for IO the state notion is not too shabby either as a first try by the way, if we think of the "real world" being the state. This is an intuition I can easily prove wrong, but I think I would rob you of some valuable learning process as monochrom as pointed out earlier. |
2025-01-31 01:31:25 +0100 | <hololeap> | it stands for "transformer" |