Logs: freenode/#haskell
| 2020-11-13 16:07:11 | × | bifunc2 quits (bifunc2@gateway/vpn/protonvpn/bifunc2) (Quit: -) |
| 2020-11-13 16:08:53 | <ski> | baidobz : fwiw, in general, instead of `sequence (fmap f xs)', you can do `mapM f xs'. but from what you're saying, it sounds like you want to use `ExceptT'. but let's see the code ? |
| 2020-11-13 16:09:39 | <tomsmeding> | I suspect that the relevant code looks like 'sequence <$> mapM action list' |
| 2020-11-13 16:09:42 | <mtothem> | How can i import a local haskell module to my xmonad.hs? |
| 2020-11-13 16:09:48 | <ski> | (something like `runExceptT (mapM (ExceptT . f) xs)') |
| 2020-11-13 16:09:59 | → | Ariakenom joins (~Ariakenom@h-82-196-111-82.NA.cust.bahnhof.se) |
| 2020-11-13 16:10:07 | <ski> | mtothem : `import MyModule' ? |
| 2020-11-13 16:10:15 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 265 seconds) |
| 2020-11-13 16:10:57 | × | quinn quits (~quinn@c-73-223-224-163.hsd1.ca.comcast.net) (Ping timeout: 244 seconds) |
| 2020-11-13 16:11:07 | <ski> | tomsmeding : hm, sounds likely |
| 2020-11-13 16:11:51 | <mtothem> | I've been trying to do that. but it doesn't work for some reason. it does in other projects. so maybe xmonad does something differently i'm thinking |
| 2020-11-13 16:12:02 | <ski> | what is the other file named ? |
| 2020-11-13 16:12:19 | <mtothem> | `colorscheme.hs` ski |
| 2020-11-13 16:12:36 | <ski> | try naming it `ColorScheme.hs', and do `import ColorScheme' ? |
| 2020-11-13 16:12:41 | → | Sanchayan joins (~Sanchayan@171.61.102.109) |
| 2020-11-13 16:13:04 | <tomsmeding> | (the initial letter of a module name must be a capital letter, the "S" doesn't matter) |
| 2020-11-13 16:13:27 | × | Sanchayan quits (~Sanchayan@171.61.102.109) (Read error: Connection reset by peer) |
| 2020-11-13 16:13:30 | <mtothem> | `Could not find module ColorScheme` |
| 2020-11-13 16:13:31 | <ski> | (unless it's the main module of an executable) |
| 2020-11-13 16:13:49 | <tomsmeding> | (or you're using a case-insensitive file system, like is the default on macOS) |
| 2020-11-13 16:13:51 | <ski> | you renamed the file ? |
| 2020-11-13 16:13:54 | <ski> | yea |
| 2020-11-13 16:14:09 | × | berberman quits (~berberman@unaffiliated/berberman) (Quit: ZNC 1.7.5 - https://znc.in) |
| 2020-11-13 16:14:38 | → | berberman joins (~berberman@unaffiliated/berberman) |
| 2020-11-13 16:16:26 | → | quinn joins (~quinn@c-73-223-224-163.hsd1.ca.comcast.net) |
| 2020-11-13 16:17:11 | <baidobz> | tomsmeding: ski: This is what I'm playing around with now: https://pastebin.com/A2MhUdC8 |
| 2020-11-13 16:18:06 | <tomsmeding> | baidobz: yes try ski's suggestion with ExceptT |
| 2020-11-13 16:18:07 | <baidobz> | Basically I would like to short-circuit the processing of the list elements in IO upon any error |
| 2020-11-13 16:18:29 | ski | low fours tomsmeding |
| 2020-11-13 16:18:29 | <tomsmeding> | (import Control.Monad.Except from the 'mtl' package) |
| 2020-11-13 16:18:56 | <ski> | baidobz : but first replace `sequence (map f xs)' by `mapM f xs' |
| 2020-11-13 16:19:16 | <tomsmeding> | (not necessary, it means the same, but it's neater) |
| 2020-11-13 16:19:20 | <baidobz> | Great I'll try that, thank you |
| 2020-11-13 16:21:02 | <ski> | baidobz : you could change the signature to `runFoo :: Text -> ExceptT MyErr IO Text', if you like to |
| 2020-11-13 16:21:52 | × | zaquest quits (~notzaques@5.128.210.178) (Quit: Leaving) |
| 2020-11-13 16:22:12 | <ski> | (if it's likely that you'd want to call `runFoo' in a context where you'd want to continue doing some possibly-aborting execution (assuming the `runFoo' invocation didn't abort), then i'd do that) |
| 2020-11-13 16:22:59 | <baidobz> | Indeed that worked! How come it does not work with a plain map and sequence? Where does the short-circuiting logic come from? |
| 2020-11-13 16:23:04 | × | christo quits (~chris@81.96.113.213) (Remote host closed the connection) |
| 2020-11-13 16:23:39 | <tomsmeding> | ExceptT explicitly stops executing remaining monadic actions if a Left occurs |
| 2020-11-13 16:23:43 | <baidobz> | The bind of MonadError? |
| 2020-11-13 16:24:04 | <tomsmeding> | normally, the mapM (or in your original version, the 'sequence') would first evaluate all monadic actions, and only when those are complete return the resulting list |
| 2020-11-13 16:24:05 | <tomsmeding> | yup |
| 2020-11-13 16:24:06 | → | zaquest joins (~notzaques@5.128.210.178) |
| 2020-11-13 16:24:10 | × | zaquest quits (~notzaques@5.128.210.178) (Read error: Connection reset by peer) |
| 2020-11-13 16:24:30 | <ski> | it comes from using the `ExceptT' version of `sequence'/`mapM', which ultimately comes from the `Applicative' / `Monad' instance for `ExceptT' being short-circuiting |
| 2020-11-13 16:25:15 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-11-13 16:26:30 | <ski> | (`traverse' (or `sequenceA') is a version of `mapM' (or `sequence') which only requires `Applicative', not `Monad'. back when `sequence'/`mapM' was defined, `Applicative' didn't exist yet, so now you have both those, and `sequenceA'/`traverse') |
| 2020-11-13 16:27:15 | <ski> | baidobz : `MonadError' doesn't come to play here |
| 2020-11-13 16:27:46 | → | gproto023 joins (~gproto23@unaffiliated/gproto23) |
| 2020-11-13 16:28:45 | → | LKoen joins (~LKoen@9.253.88.92.rev.sfr.net) |
| 2020-11-13 16:29:43 | → | gproto0023 joins (~gproto23@unaffiliated/gproto23) |
| 2020-11-13 16:30:38 | × | kav quits (~kari@dsl-hkibng42-56733f-225.dhcp.inet.fi) (Ping timeout: 264 seconds) |
| 2020-11-13 16:30:40 | → | zaquest joins (~notzaques@5.128.210.178) |
| 2020-11-13 16:31:01 | → | Martinsos joins (~user@cpe-188-129-116-164.dynamic.amis.hr) |
| 2020-11-13 16:31:26 | <baidobz> | Super interesting. I'm looking at the Haddock and mtl's sources to try and find the relevant definition in the code now |
| 2020-11-13 16:32:05 | × | gproto023 quits (~gproto23@unaffiliated/gproto23) (Ping timeout: 240 seconds) |
| 2020-11-13 16:32:18 | <tomsmeding> | https://hackage.haskell.org/package/transformers-0.5.6.2/docs/src/Control.Monad.Trans.Except.html#line-212 |
| 2020-11-13 16:32:25 | <baidobz> | I guess it's in transformers |
| 2020-11-13 16:32:37 | <baidobz> | Yes! Thanks :) |
| 2020-11-13 16:33:20 | <tomsmeding> | it's refreshing how readable basic definitions like these are, the short-circuiting is actually evident in the definition of >>= (which is only 5 lines) |
| 2020-11-13 16:33:36 | <tomsmeding> | contrast with e.g. C++ standard libraries... |
| 2020-11-13 16:34:10 | <baidobz> | Indeed it's very simple and clear |
| 2020-11-13 16:34:48 | <baidobz> | I used to do lots of template meta-programming in C++ and I don't miss it |
| 2020-11-13 16:35:01 | → | Chi1thangoo joins (~Chi1thang@87.112.60.168) |
| 2020-11-13 16:35:17 | × | conal quits (~conal@66.115.157.159) (Quit: Computer has gone to sleep.) |
| 2020-11-13 16:35:49 | <baidobz> | Thanks a lot for your quick help! |
| 2020-11-13 16:36:12 | → | Martinsos_ joins (~Martinsos@cpe-188-129-116-164.dynamic.amis.hr) |
| 2020-11-13 16:36:55 | <baidobz> | Can I also ask: is there a situation (different Monad?) where my naive approach with sequence would work out similarly due to laziness or does sequence/mapM always evaluate all monadic actions? |
| 2020-11-13 16:37:28 | <comerijn> | baidobz: The ordering of effects is independent of laziness |
| 2020-11-13 16:37:34 | <ski> | it always executes all the actions (performing all the effects) |
| 2020-11-13 16:37:59 | <comerijn> | baidobz: The Monad/Applicative instance of, say, IO are always in sequential order |
| 2020-11-13 16:38:01 | <ski> | but yes, non-strictness is a separate thing |
| 2020-11-13 16:38:48 | <solonarv> | well, no. sequence [System.Exit.exit, putStrLn "hello"] will not output hello to the terminal, for a counterexample |
| 2020-11-13 16:38:49 | × | Martinsos_ quits (~Martinsos@cpe-188-129-116-164.dynamic.amis.hr) (Client Quit) |
| 2020-11-13 16:38:59 | <comerijn> | baidobz: So yes, sequence and mapM guarantee that all the actions are done by the time the sequence/mapM is done |
| 2020-11-13 16:39:03 | <comerijn> | solonarv: >.> |
| 2020-11-13 16:39:15 | ← | Martinsos parts (~user@cpe-188-129-116-164.dynamic.amis.hr) ("ERC (IRC client for Emacs 27.1)") |
| 2020-11-13 16:39:21 | <comerijn> | solonarv: That's not a contradiction, anyway |
| 2020-11-13 16:39:31 | hackage | polysemy-methodology-composite 0.1.0.0 - Functions for using polysemy-methodology with composite. https://hackage.haskell.org/package/polysemy-methodology-composite-0.1.0.0 (locallycompact) |
| 2020-11-13 16:39:47 | <comerijn> | solonarv: exit happens in sequential order with the rest :p |
| 2020-11-13 16:39:49 | <solonarv> | depending on which Monad instance is being used, the later ones may or may not be exexucted, or evaluated |
| 2020-11-13 16:40:03 | <solonarv> | (however the *order* does not depend on which instance is in play) |
| 2020-11-13 16:40:29 | <ski> | oh, good example. i suppose one should say that each action is executed, provided all the previous ones terminated normally |
| 2020-11-13 16:40:44 | → | nbloomf joins (~nbloomf@2600:1700:ad14:3020:b423:9089:de01:217e) |
| 2020-11-13 16:41:01 | hackage | polysemy-methodology-composite 0.1.1.0 - Functions for using polysemy-methodology with composite. https://hackage.haskell.org/package/polysemy-methodology-composite-0.1.1.0 (locallycompact) |
| 2020-11-13 16:41:04 | → | xerox_ joins (~xerox@unaffiliated/xerox) |
| 2020-11-13 16:41:14 | <solonarv> | they're executed in order, but an action might say "exit immediately, nothing after me gets executed" or even "everything after me happens twice" or "everything after me happens on another thread" |
| 2020-11-13 16:41:32 | <ski> | (obviously when executing `do foo; undefined; bar', `bar' will not be executed, at least in general) |
| 2020-11-13 16:42:00 | <ski> | yes, which is exactly what `ExceptT' does (the "nothing after me gets executed" part) |
| 2020-11-13 16:42:31 | hackage | polysemy-methodology-composite 0.1.2.0 - Functions for using polysemy-methodology with composite. https://hackage.haskell.org/package/polysemy-methodology-composite-0.1.2.0 (locallycompact) |
| 2020-11-13 16:42:41 | <solonarv> | yep; the other two can be accomplished by Cont / ContT, and probably also by a number of other monads |
| 2020-11-13 16:42:56 | <ski> | yep (i see how one could accomplish it) |
| 2020-11-13 16:43:25 | × | avdb quits (~avdb@ip-213-49-124-119.dsl.scarlet.be) (Ping timeout: 240 seconds) |
| 2020-11-13 16:43:28 | <baidobz> | Great points, that makes sense |
| 2020-11-13 16:43:31 | hackage | cabal-file 0.1.1 - Cabal file access https://hackage.haskell.org/package/cabal-file-0.1.1 (JensPetersen) |
| 2020-11-13 16:45:46 | → | Martinsos joins (~user@cpe-188-129-116-164.dynamic.amis.hr) |
| 2020-11-13 16:46:06 | ← | Martinsos parts (~user@cpe-188-129-116-164.dynamic.amis.hr) () |
| 2020-11-13 16:46:25 | <motte> | hekkaidekapus: >[[(1 :: Int) .. 4], [5 .. 13]] |
| 2020-11-13 16:46:29 | <ski> | in `do n <- [1 .. 9]; d <- [2 .. n-1]; guard (n `mod` d == 0); return (n,d)', for some choice of `n' (namely `1'), everything after `d <- [2 .. n-1]' will be executed zero times (iow, we abort that choice of `n'), and for some other choices of `n', what's after will be executed several times |
| 2020-11-13 16:47:31 | <ski> | (and then, similarly, for different choices of `d', what comes after the `guard' invocation may be executed once or not at all) |
All times are in UTC.