Logs: freenode/#haskell
| 2020-10-03 00:23:30 | <ski> | @let partition' p xs = foldr (select' p) ([],[]) xs where select' p x (ts,fs) | p x = (x:ts,fs) | otherwise = (ts,x:fs) |
| 2020-10-03 00:23:32 | <lambdabot> | Defined. |
| 2020-10-03 00:23:56 | <ski> | which is what you get, if you remove the lazy / irrefutable pattern `~<pat>' from the former |
| 2020-10-03 00:23:59 | <ski> | now, we get |
| 2020-10-03 00:24:03 | → | fendor_ joins (~fendor@91.141.0.198.wireless.dyn.drei.com) |
| 2020-10-03 00:24:04 | <ski> | > let (evens,odds) = partition' even [0 ..] in (take 4 evens,take 4 odds) |
| 2020-10-03 00:24:11 | <lambdabot> | mueval-core: Time limit exceeded |
| 2020-10-03 00:24:33 | × | GyroW_ quits (~GyroW@unaffiliated/gyrow) (Quit: Someone ate my pie) |
| 2020-10-03 00:24:34 | <ski> | in this case (passing an infinite list as input), it's crucial to have the `~' here ! |
| 2020-10-03 00:24:50 | → | GyroW joins (~GyroW@ptr-48ujrfd1ztq5fjywfw3.18120a2.ip6.access.telenet.be) |
| 2020-10-03 00:24:50 | × | GyroW quits (~GyroW@ptr-48ujrfd1ztq5fjywfw3.18120a2.ip6.access.telenet.be) (Changing host) |
| 2020-10-03 00:24:50 | → | GyroW joins (~GyroW@unaffiliated/gyrow) |
| 2020-10-03 00:25:01 | <ski> | also, for a long, but finite list, partition will produce output, before seeing the end, but partition' won't ! |
| 2020-10-03 00:25:29 | <koz_> | ski: OK, that makes sense, and is very interesting. |
| 2020-10-03 00:25:32 | <koz_> | Thank you! |
| 2020-10-03 00:26:12 | <ski> | (and if you use `readFile' or `getContents' to process a file that's very big, possibly even too large to fit into memory all at once (lazy I/O), you don't want to have to see the end of the list, before you can produce some part of the output. you want to be "incremental", rather than "bulky". partition is incremental) |
| 2020-10-03 00:26:39 | × | fendor quits (~fendor@91.141.2.239.wireless.dyn.drei.com) (Ping timeout: 265 seconds) |
| 2020-10-03 00:27:01 | <ski> | the problem is that, if you're just matching on `(ts,fs)', you're actually matching on the recursive call to `foldr'. so, you're forcing `foldr' to get to the end of the list, before you can output the current element `x' in one or the other of the output lists |
| 2020-10-03 00:27:24 | <ski> | by matching on `~(ts,fs)', you delay that forcing of the recursive call |
| 2020-10-03 00:27:27 | <ski> | @src foldr |
| 2020-10-03 00:27:27 | <lambdabot> | foldr f z [] = z |
| 2020-10-03 00:27:27 | <lambdabot> | foldr f z (x:xs) = f x (foldr f z xs) |
| 2020-10-03 00:28:02 | <ski> | in this case, `~(ts,fs)' is perfectly safe, since there's no way that matching on `(ts,fs') (later) can fail with a pattern-match error |
| 2020-10-03 00:28:46 | <ski> | now .. lazy patterns aren't required that often. but when there's a situation that calls for them, they can help make the code more readable |
| 2020-10-03 00:29:31 | <ski> | insyead of `select p x ~(ts,fs) = ..ts..fs..' here, we could have said `select p x tsfs = ..(fst tsfs)..(snd tsfs)..', and it would also have worked |
| 2020-10-03 00:29:48 | → | carlomagno joins (~cararell@inet-hqmc02-o.oracle.com) |
| 2020-10-03 00:30:48 | <ski> | or, instead of `foo ~(x:xs) = ..x..xs..', one could say `foo xs0 = ..x..xs.. where (x,xs) = case xs0 of x:xs -> (x,xs)' (or `foo xs0 = ..(case xs0 of x:_ -> x)..(case xs0 of _:xs -> xs)..') |
| 2020-10-03 00:31:07 | <ski> | however, the first is more readable |
| 2020-10-03 00:32:40 | × | dhil quits (~dhil@11.29.39.217.dyn.plus.net) (Ping timeout: 256 seconds) |
| 2020-10-03 00:35:35 | → | ahmr88 joins (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) |
| 2020-10-03 00:35:48 | <cohn> | for anyone that's familiar with the Wreq HTTP library: when you use a lens on a nested object, how do you get the values out? |
| 2020-10-03 00:37:25 | <dsal> | What do you mean? |
| 2020-10-03 00:38:08 | × | AlterEgo- quits (~ladew@124-198-158-163.dynamic.caiway.nl) (Quit: Leaving) |
| 2020-10-03 00:38:13 | <dsal> | cohn: I have a few helpers: https://github.com/dustin/gopro-plus/blob/master/src/GoPro/Plus/Internal/HTTP.hs |
| 2020-10-03 00:38:33 | <cohn> | dsal: so if I have some json data like '{"foo": ["bar", "baz"]}' the array seems to get transformed into a Vector. How would I get the values out? |
| 2020-10-03 00:39:14 | → | da39a3ee5e6b4b0d joins (~textual@n11211935170.netvigator.com) |
| 2020-10-03 00:40:38 | <dsal> | I think I'd probably use `toListOf` |
| 2020-10-03 00:40:54 | <cohn> | hmm. okay |
| 2020-10-03 00:40:56 | <dsal> | I'm looking for a simple example, but none of my examples end up being quite simple enough. |
| 2020-10-03 00:41:34 | <cohn> | exactly my dilemma. : ( |
| 2020-10-03 00:41:43 | <dsal> | Maybe this one: https://github.com/dustin/gopro-plus/blob/master/src/GoPro/Plus/Media.hs#L173-L180 |
| 2020-10-03 00:42:49 | × | cr3 quits (~cr3@192-222-143-195.qc.cable.ebox.net) (Ping timeout: 264 seconds) |
| 2020-10-03 00:43:02 | <cohn> | that's promising. Thanks! |
| 2020-10-03 00:44:37 | <dsal> | I was hoping one of the bots had Aeson, but `toListOf` is your friend here. |
| 2020-10-03 00:44:52 | <dsal> | Or just use the vector, but that can be annoying sometimes. |
| 2020-10-03 00:45:09 | <dsal> | Or make a custom type and let it parse into that. I guess it depends on what you actual want. |
| 2020-10-03 00:45:32 | <cohn> | for now, just trying to learn Aeson and Wreq on some play data |
| 2020-10-03 00:45:47 | × | todda7 quits (~torstein@athedsl-4367507.home.otenet.gr) (Ping timeout: 240 seconds) |
| 2020-10-03 00:46:16 | <dsal> | Much of mine ends up accessing custom types. Aeson will run my FromJSON code and just give me a value of my type. |
| 2020-10-03 00:46:38 | <dsal> | I do occasionally play with the underlying Aeson Value thing, though. |
| 2020-10-03 00:46:39 | <cohn> | I'll probably need to do the same |
| 2020-10-03 00:46:42 | → | cr3 joins (~cr3@192-222-143-195.qc.cable.ebox.net) |
| 2020-10-03 00:46:51 | <dsal> | Doing the "hard" thing may very well save you a lot of time and confusion. |
| 2020-10-03 00:47:01 | × | conal quits (~conal@107.181.166.148) (Quit: Computer has gone to sleep.) |
| 2020-10-03 00:47:35 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2020-10-03 00:47:40 | × | jedws quits (~jedws@121.209.139.222) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2020-10-03 00:47:44 | <dsal> | Aeson lens is cool when you really want to just pull a smaller blob out of a big wad of JSON. But if you have a regular form you intend to do a lot with, you'll find the long road shorter. :) |
| 2020-10-03 00:48:21 | <cohn> | I was hoping to avoid actually having to write a bunch of code just to play around with some data but I think you're right. |
| 2020-10-03 00:49:51 | <dsal> | You can do it in lens code, or you can do it in type code. If you're in a repl, the lens stuff might be easier. If you're in a file, defining a type is straightforward unless you need to do some custom decoding. |
| 2020-10-03 00:50:07 | <cohn> | I will say though, Wreq + Aeson + Lens makes this MUCH less painful. |
| 2020-10-03 00:50:35 | <cohn> | I might need some custom decoding for a few things, but I think I have everything I need. |
| 2020-10-03 00:50:47 | <dsal> | cohn: e.g., much of my code looks something like this: https://github.com/dustin/tesla/blob/master/src/Tesla/Car.hs#L215-L228 |
| 2020-10-03 00:51:47 | <dsal> | Actually, from about there down is defining a sum type for two different types of results, making a request with wreq, and returning a list of the things of my type. |
| 2020-10-03 00:52:00 | <cohn> | ooh, nice |
| 2020-10-03 00:52:17 | <dsal> | (the two functions in the middle aren't actually part of this, just helpers for looking at only one type or other based on the prism) |
| 2020-10-03 00:54:38 | <cohn> | prism? |
| 2020-10-03 00:55:54 | → | johanna joins (~johanna@s91904426.blix.com) |
| 2020-10-03 00:59:38 | × | GyroW quits (~GyroW@unaffiliated/gyrow) (Quit: Someone ate my pie) |
| 2020-10-03 00:59:48 | → | GyroW joins (~GyroW@d54C03E98.access.telenet.be) |
| 2020-10-03 00:59:48 | × | GyroW quits (~GyroW@d54C03E98.access.telenet.be) (Changing host) |
| 2020-10-03 00:59:48 | → | GyroW joins (~GyroW@unaffiliated/gyrow) |
| 2020-10-03 01:06:31 | × | berberman quits (~berberman@2408:8207:2562:2400::a44) (Ping timeout: 272 seconds) |
| 2020-10-03 01:07:17 | → | Jeanne-Kamikaze joins (~Jeanne-Ka@68.235.43.94) |
| 2020-10-03 01:07:43 | → | aarvar joins (~foewfoiew@50.35.43.33) |
| 2020-10-03 01:18:20 | × | raehik quits (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) (Read error: Connection reset by peer) |
| 2020-10-03 01:18:25 | → | raehik1 joins (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) |
| 2020-10-03 01:20:25 | × | xff0x quits (~fox@2001:1a81:5254:9a00:e9b2:76ba:9f0:a22b) (Ping timeout: 240 seconds) |
| 2020-10-03 01:21:36 | → | xff0x joins (~fox@2001:1a81:5254:9a00:acd2:8569:1d0e:86f) |
| 2020-10-03 01:22:20 | × | cosimone quits (~cosimone@2001:b07:ae5:db26:b248:7aff:feea:34b6) (Quit: Quit.) |
| 2020-10-03 01:25:56 | → | HaskellYogi joins (~vivekrama@49.207.196.239) |
| 2020-10-03 01:29:57 | → | AlterEgo- joins (~ladew@124-198-158-163.dynamic.caiway.nl) |
| 2020-10-03 01:30:58 | × | HaskellYogi quits (~vivekrama@49.207.196.239) (Ping timeout: 260 seconds) |
| 2020-10-03 01:31:42 | → | HaskellYogi joins (~vivekrama@49.207.196.239) |
| 2020-10-03 01:33:09 | → | HarveyPwca joins (~HarveyPwc@c-98-220-98-201.hsd1.il.comcast.net) |
| 2020-10-03 01:36:27 | × | HaskellYogi quits (~vivekrama@49.207.196.239) (Ping timeout: 260 seconds) |
| 2020-10-03 01:37:17 | → | HaskellYogi joins (~vivekrama@49.207.196.239) |
| 2020-10-03 01:42:03 | × | HaskellYogi quits (~vivekrama@49.207.196.239) (Ping timeout: 260 seconds) |
| 2020-10-03 01:42:52 | → | HaskellYogi joins (~vivekrama@49.207.196.239) |
| 2020-10-03 01:45:45 | × | mav1 quits (~mav@i59F456E0.versanet.de) (Ping timeout: 240 seconds) |
| 2020-10-03 01:46:25 | × | raehik1 quits (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) (Ping timeout: 240 seconds) |
| 2020-10-03 01:47:55 | × | xff0x quits (~fox@2001:1a81:5254:9a00:acd2:8569:1d0e:86f) (Ping timeout: 240 seconds) |
| 2020-10-03 01:49:47 | → | xff0x joins (~fox@2001:1a81:528f:c400:acd2:8569:1d0e:86f) |
| 2020-10-03 01:54:28 | → | Stanley00 joins (~stanley00@unaffiliated/stanley00) |
| 2020-10-03 01:54:50 | × | ahmr88 quits (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) (Remote host closed the connection) |
| 2020-10-03 01:56:24 | <dsal> | cohn: Sorry, went outside for a bit. |
| 2020-10-03 01:56:27 | <dsal> | > [Right 1, Right 2, Left 3, Right 4, Left 5] ^.. folded . _Right |
| 2020-10-03 01:56:29 | <lambdabot> | [1,2,4] |
| 2020-10-03 01:57:18 | <dsal> | prism is a concept in optics that lets you do fun things with sum types. |
| 2020-10-03 01:58:44 | × | tsrt^ quits (tsrt@ip98-184-89-2.mc.at.cox.net) () |
| 2020-10-03 01:59:32 | <cohn> | ah |
All times are in UTC.