Logs: liberachat/#haskell
| 2021-06-07 13:49:50 | <dminuoso> | getParam :: Int -> [Maybe a] -> IO a; getParam p xs = maybe (fail ("Missing parameter " <> show p)) pure (xs !! p) |
| 2021-06-07 13:49:59 | × | madnight quits (~madnight@static.59.103.201.195.clients.your-server.de) (Quit: ZNC 1.7.1 - https://znc.in) |
| 2021-06-07 13:50:09 | <dminuoso> | guest61: ^- this is not an elegant final solution, but this little combinator will let you avoid a lot of pain here. |
| 2021-06-07 13:50:11 | → | madnight joins (~madnight@static.59.103.201.195.clients.your-server.de) |
| 2021-06-07 13:50:13 | × | safinaskar quits (~safinaska@109-252-90-89.nat.spd-mgts.ru) (Quit: Client closed) |
| 2021-06-07 13:50:16 | <dminuoso> | Then you can write code in this style: |
| 2021-06-07 13:50:41 | × | hendursa1 quits (~weechat@user/hendursaga) (Quit: hendursa1) |
| 2021-06-07 13:51:19 | → | hendursaga joins (~weechat@user/hendursaga) |
| 2021-06-07 13:51:41 | <guest61> | but those variables are need in the rest code, they can't be IO a, They need to be Text |
| 2021-06-07 13:51:56 | <dminuoso> | do { let param p = getParam p checkParameters; mode <- param 0; server <- param 1; ... password <- maybe (pure "") pure (checkParameters !! 4); ... } |
| 2021-06-07 13:51:56 | → | ddellacosta joins (~ddellacos@86.106.143.61) |
| 2021-06-07 13:51:58 | <guest61> | otherwise I need to change a lot functions |
| 2021-06-07 13:51:58 | <dminuoso> | guest61: ^- |
| 2021-06-07 13:52:59 | × | pe200012_ quits (~pe200012@58.248.179.178) (Ping timeout: 245 seconds) |
| 2021-06-07 13:53:19 | → | pe200012_ joins (~pe200012@120.236.162.3) |
| 2021-06-07 13:53:21 | <dminuoso> | guest61: This has the added benefit of giving a graceful error, if due to some unforseen circumstance (perhaps you missed a Nothing, or a parameter got removed/added) there's suddenly an unexpected Nothing. |
| 2021-06-07 13:53:27 | × | oxide quits (~lambda@user/oxide) (Ping timeout: 252 seconds) |
| 2021-06-07 13:53:48 | <ski> | let password = fromMaybe ""(checkParameters !! 4) |
| 2021-06-07 13:54:13 | <dminuoso> | ^- this is more a drop-in replacement for what you have, without addressing the rest. |
| 2021-06-07 13:54:19 | <dminuoso> | Oh, I guess I should have written: |
| 2021-06-07 13:54:27 | <dminuoso> | do { let param p = getParam p checkParameters; mode <- param 0; server <- param 1; ... password <- fromMaybe "" pure (checkParameters !! 4); ... } |
| 2021-06-07 13:54:29 | → | geekosaur joins (~geekosaur@069-135-003-034.biz.spectrum.com) |
| 2021-06-07 13:54:29 | <dminuoso> | Thanks, ski. |
| 2021-06-07 13:54:31 | <guest61> | fromMaybe is better |
| 2021-06-07 13:54:37 | <guest61> | than my fromJust |
| 2021-06-07 13:55:14 | <guest61> | what's this do ? Maybe or IO? |
| 2021-06-07 13:55:37 | <dminuoso> | % :t fromMaybe |
| 2021-06-07 13:55:37 | <yahb> | dminuoso: a -> Maybe a -> a |
| 2021-06-07 13:55:38 | <guest61> | oh IO |
| 2021-06-07 13:55:49 | <dminuoso> | oh hah wait |
| 2021-06-07 13:55:57 | <dminuoso> | do { let param p = getParam p checkParameters; mode <- param 0; server <- param 1; ... password <- fromMaybe (pure "") pure (checkParameters !! 4); ... } |
| 2021-06-07 13:55:59 | <dminuoso> | Here we go. |
| 2021-06-07 13:56:19 | <dminuoso> | You could do other tricks too, like stay in Either String and collect the error there |
| 2021-06-07 13:56:43 | × | neceve quits (~quassel@2a02:c7f:607e:d600:a95a:ecd2:e57a:3130) (Ping timeout: 244 seconds) |
| 2021-06-07 13:57:04 | × | ddellacosta quits (~ddellacos@86.106.143.61) (Ping timeout: 272 seconds) |
| 2021-06-07 13:57:13 | <guest61> | no need, just simple Text is what other functions need, no more wrapped |
| 2021-06-07 13:57:40 | <guest61> | otherwise I need to change a lot of functions |
| 2021-06-07 13:59:02 | <ski> | better with `let' than `<-' and `pure', for `password' |
| 2021-06-07 14:00:46 | → | Lycurgus joins (~juan@cpe-45-46-140-49.buffalo.res.rr.com) |
| 2021-06-07 14:01:05 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2021-06-07 14:01:54 | <guest61> | if there's Nothing in thst list, so it would return "missing parameter"? |
| 2021-06-07 14:02:38 | <guest61> | But there's another questions, see my second paste, the missing msg is different |
| 2021-06-07 14:03:06 | <guest61> | missing different variables, show different msg |
| 2021-06-07 14:03:39 | <guest61> | oh you did |
| 2021-06-07 14:03:54 | <guest61> | I forgot <> p |
| 2021-06-07 14:04:18 | <guest61> | that's more elegant |
| 2021-06-07 14:05:04 | <guest61> | I will try it later, thanks, dminuoso, ski |
| 2021-06-07 14:06:35 | <ski> | guest61 : what's the length of `checkParameters' ? |
| 2021-06-07 14:06:35 | × | o1lo01ol1o quits (~o1lo01ol1@c-73-10-81-85.hsd1.nj.comcast.net) (Ping timeout: 245 seconds) |
| 2021-06-07 14:07:08 | <guest61> | 8 |
| 2021-06-07 14:08:17 | → | yoctocell joins (~user@h87-96-130-155.cust.a3fiber.se) |
| 2021-06-07 14:08:24 | × | azeem quits (~azeem@176.201.37.236) (Ping timeout: 245 seconds) |
| 2021-06-07 14:09:45 | <guest61> | ghc tells me <|> is ambitious, there are Control.Applicative and Text.ParserComBinators.Parsec.<|>, but I don't want to qualified Control.Applivative neither Parsec |
| 2021-06-07 14:09:58 | <guest61> | any suggestions? |
| 2021-06-07 14:10:43 | <guest61> | why <|> could be like id? |
| 2021-06-07 14:10:46 | → | azeem joins (~azeem@176.201.16.12) |
| 2021-06-07 14:10:50 | <guest61> | id is so arbi |
| 2021-06-07 14:10:52 | <guest61> | arbitrary |
| 2021-06-07 14:10:58 | → | o1lo01ol1o joins (~o1lo01ol1@c-73-10-81-85.hsd1.nj.comcast.net) |
| 2021-06-07 14:11:24 | <guest61> | not |
| 2021-06-07 14:14:44 | → | Sgeo joins (~Sgeo@user/sgeo) |
| 2021-06-07 14:15:27 | <yushyin> | guest61: usually import the <|> from control.applicative unqualified and others qualified but with a shorter renamed namespace |
| 2021-06-07 14:16:05 | <guest61> | yeah, I hate that |
| 2021-06-07 14:16:28 | <yushyin> | you can also hide the other <|> and not import it at all |
| 2021-06-07 14:17:11 | <guest61> | but <|> from Control and Text both are used |
| 2021-06-07 14:18:52 | <Lycurgus> | ambitious |
| 2021-06-07 14:19:04 | <Lycurgus> | hubristic even |
| 2021-06-07 14:23:14 | → | fizbin joins (~fizbin@2600:1002:b128:230e:1cbd:13c5:3322:f6cc) |
| 2021-06-07 14:24:13 | × | ddellaco_ quits (~ddellacos@89.46.62.69) (Remote host closed the connection) |
| 2021-06-07 14:24:41 | → | ddellacosta joins (~ddellacos@89.46.62.69) |
| 2021-06-07 14:26:25 | → | oxide joins (~lambda@user/oxide) |
| 2021-06-07 14:26:57 | → | jneira joins (~jneira@166.red-81-39-172.dynamicip.rima-tde.net) |
| 2021-06-07 14:28:19 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-06-07 14:28:29 | <yushyin> | You could define another operator as an alias to one of the others. |
| 2021-06-07 14:28:54 | <DigitalKiwi> | <|> voted most likely to succeed in the year book |
| 2021-06-07 14:29:22 | × | ddellacosta quits (~ddellacos@89.46.62.69) (Ping timeout: 272 seconds) |
| 2021-06-07 14:29:46 | × | ukari quits (~ukari@user/ukari) (Remote host closed the connection) |
| 2021-06-07 14:30:10 | → | ukari joins (~ukari@user/ukari) |
| 2021-06-07 14:30:41 | <boxscape> | Guest2041 you should be able to use Control.Applicative's for both, I think? There is an `Alternative` instance for Parsec |
| 2021-06-07 14:30:48 | → | zeenk joins (~zeenk@2a02:2f04:a310:b600:b098:bf18:df4d:4c41) |
| 2021-06-07 14:30:49 | <boxscape> | uhh, wrong guest, sorry |
| 2021-06-07 14:30:52 | <boxscape> | guest61 |
| 2021-06-07 14:33:16 | × | Brumaire quits (~quassel@81-64-14-121.rev.numericable.fr) (Remote host closed the connection) |
| 2021-06-07 14:33:19 | × | dunkeln quits (~dunkeln@94.129.65.28) (Ping timeout: 264 seconds) |
| 2021-06-07 14:33:38 | → | ddellacosta joins (~ddellacos@89.46.62.86) |
| 2021-06-07 14:35:42 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 272 seconds) |
| 2021-06-07 14:37:01 | <yushyin> | if that's the case, it's very likely the same implementation, yup. |
| 2021-06-07 14:37:15 | × | ddellacosta quits (~ddellacos@89.46.62.86) (Remote host closed the connection) |
| 2021-06-07 14:37:43 | → | ddellacosta joins (~ddellacos@89.46.62.86) |
| 2021-06-07 14:37:52 | <boxscape> | yeah I checked, they're both implemented as mplus |
| 2021-06-07 14:37:57 | <geekosaur> | I* was under the (possibly incorrect) impression the Parsec one is monadic, for performance reasons |
| 2021-06-07 14:37:59 | <geekosaur> | ah |
| 2021-06-07 14:42:24 | × | ddellacosta quits (~ddellacos@89.46.62.86) (Ping timeout: 252 seconds) |
| 2021-06-07 14:42:50 | → | ddellacosta joins (~ddellacos@89.46.62.34) |
| 2021-06-07 14:43:10 | × | Lycurgus quits (~juan@cpe-45-46-140-49.buffalo.res.rr.com) (Quit: Exeunt) |
| 2021-06-07 14:43:30 | × | azeem quits (~azeem@176.201.16.12) (Ping timeout: 252 seconds) |
| 2021-06-07 14:45:19 | × | fluffyballoon quits (~fluffybal@2620:72:0:6480::e5) (Quit: Client closed) |
| 2021-06-07 14:47:40 | → | azeem joins (~azeem@176.201.16.12) |
| 2021-06-07 14:48:03 | → | ddellaco_ joins (~ddellacos@89.46.62.34) |
| 2021-06-07 14:48:14 | → | hiptobecubic joins (~john@c-73-55-99-95.hsd1.fl.comcast.net) |
All times are in UTC.