Logs: freenode/#haskell
| 2021-04-03 02:11:54 | → | shalokshalom joins (~quassel@2a02:1748:dd5e:7f60:cf49:8384:7c93:3106) |
| 2021-04-03 02:15:35 | × | caef^ quits (caef@ip98-184-89-2.mc.at.cox.net) () |
| 2021-04-03 02:20:22 | × | Achylles quits (~Achylles@2804:431:d725:7a65:e4bb:fb4:b1ea:8d3b) (Read error: Connection reset by peer) |
| 2021-04-03 02:21:24 | → | DTZUZU joins (~DTZUZO@205.ip-149-56-132.net) |
| 2021-04-03 02:22:42 | → | MononcQc1 joins (~MononcQc@139.28.218.148) |
| 2021-04-03 02:23:38 | × | DTZUZU_ quits (~DTZUZO@207.81.119.43) (Ping timeout: 240 seconds) |
| 2021-04-03 02:23:57 | hololeap | kicks mconcat |
| 2021-04-03 02:25:05 | → | v01d4lph4 joins (~v01d4lph4@223.190.20.92) |
| 2021-04-03 02:26:26 | × | stree quits (~stree@68.36.8.116) (Ping timeout: 260 seconds) |
| 2021-04-03 02:29:41 | × | v01d4lph4 quits (~v01d4lph4@223.190.20.92) (Ping timeout: 240 seconds) |
| 2021-04-03 02:33:17 | → | nighmi joins (~felix@46.183.103.8) |
| 2021-04-03 02:33:40 | nighmi | is now known as Guest15978 |
| 2021-04-03 02:34:11 | → | Georgia joins (c634aeb5@198.52.174.181) |
| 2021-04-03 02:35:20 | <Georgia> | hey, I have the following function https://paste.tomsmeding.com/bQNEdRJ2 , could someone help me break down this list comprehension? |
| 2021-04-03 02:35:34 | × | xaltsc quits (~xaltsc@unaffiliated/xaltsc) (Read error: Connection reset by peer) |
| 2021-04-03 02:38:45 | → | drbean_ joins (~drbean@TC210-63-209-201.static.apol.com.tw) |
| 2021-04-03 02:39:14 | → | stree joins (~stree@68.36.8.116) |
| 2021-04-03 02:42:50 | <hololeap> | yeah that's a tricky one |
| 2021-04-03 02:44:06 | <hololeap> | you can write it out using a known `xs` and `n` start expanding it out |
| 2021-04-03 02:44:26 | <hololeap> | like, draw [1..10] 2 = ... |
| 2021-04-03 02:46:12 | × | andi- quits (~andi-@NixOS/user/andi-) (Remote host closed the connection) |
| 2021-04-03 02:50:40 | → | andi- joins (~andi-@NixOS/user/andi-) |
| 2021-04-03 02:51:09 | <hololeap> | :t tails [1..10] |
| 2021-04-03 02:51:10 | <lambdabot> | (Num a, Enum a) => [[a]] |
| 2021-04-03 02:51:14 | <hololeap> | > tails [1..10] |
| 2021-04-03 02:51:15 | <lambdabot> | [[1,2,3,4,5,6,7,8,9,10],[2,3,4,5,6,7,8,9,10],[3,4,5,6,7,8,9,10],[4,5,6,7,8,9... |
| 2021-04-03 02:51:36 | → | carlomagno joins (~cararell@148.87.23.10) |
| 2021-04-03 02:52:46 | <Georgia> | Trying to run it through |
| 2021-04-03 02:52:52 | <Georgia> | I'm confused by a few parts; |
| 2021-04-03 02:53:08 | <hololeap> | it's taking the first item from each inner list as t0, then doing essentially a cartisian product with `tails t (n-1)` which then does a cartesian product with `tails t (n-2)`. these cartesian products are glued together with ':' forming a list of lists |
| 2021-04-03 02:53:09 | <Georgia> | mostly this t@(t0:_) <- tails xs |
| 2021-04-03 02:53:29 | <hololeap> | not sure i can explain it much better than that |
| 2021-04-03 02:53:31 | × | howdoi quits (uid224@gateway/web/irccloud.com/x-qztqtupywnelzqgw) (Quit: Connection closed for inactivity) |
| 2021-04-03 02:54:03 | <hololeap> | s/tails t/draw t/ |
| 2021-04-03 02:54:35 | <Georgia> | what does the t@(t0:_) refer to? each of the tails outputs? |
| 2021-04-03 02:54:40 | <Georgia> | specifically the t |
| 2021-04-03 02:55:37 | <hololeap> | > let t@(t0:_) = [1,2,3,4] |
| 2021-04-03 02:55:39 | <lambdabot> | <no location info>: error: |
| 2021-04-03 02:55:39 | <lambdabot> | not an expression: ‘let t@(t0:_) = [1,2,3,4]’ |
| 2021-04-03 02:56:10 | <hololeap> | > let t@(t0:_) = [1,2,3,4] in (t, t0) |
| 2021-04-03 02:56:10 | <hololeap> | ? |
| 2021-04-03 02:56:11 | <lambdabot> | ([1,2,3,4],1) |
| 2021-04-03 02:56:25 | <Georgia> | <- does this arrow feed in each of the elements of the tails result? |
| 2021-04-03 02:57:14 | × | theDon quits (~td@muedsl-82-207-238-162.citykom.de) (Ping timeout: 260 seconds) |
| 2021-04-03 02:57:25 | <Georgia> | I'm not sure I understand how you came to the conclusion that it does a cartesian product of the two groups |
| 2021-04-03 02:57:45 | → | justanotheruser joins (~justanoth@unaffiliated/justanotheruser) |
| 2021-04-03 02:57:47 | <hololeap> | it takes a value from the list and applies it to the variable on the left side of <- and evaluates the expression. then it does this for every other element of the list on the right side of <- |
| 2021-04-03 02:58:19 | <Georgia> | and it does this crossed with rest <- ... |
| 2021-04-03 02:58:26 | <Georgia> | as per t0:rest |
| 2021-04-03 02:58:34 | <Georgia> | hence the cartesian product? |
| 2021-04-03 02:58:42 | → | theDon joins (~td@muedsl-82-207-238-112.citykom.de) |
| 2021-04-03 02:59:00 | <hololeap> | hm, do you understand the list monad? this might be hard to grasp without understanding that |
| 2021-04-03 02:59:34 | <hololeap> | list comprehensions are the same as a `do` block in the list monad |
| 2021-04-03 02:59:39 | <hololeap> | here's an example |
| 2021-04-03 02:59:57 | → | FinnElija joins (~finn_elij@gateway/tor-sasl/finnelija/x-67402716) |
| 2021-04-03 02:59:57 | finn_elija | is now known as Guest22848 |
| 2021-04-03 02:59:57 | FinnElija | is now known as finn_elija |
| 2021-04-03 03:00:22 | <hololeap> | > do x <- [1,2,3] ; y <- [4,5,6] ; return (x,y) |
| 2021-04-03 03:00:23 | <lambdabot> | [(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)] |
| 2021-04-03 03:00:44 | <hololeap> | and the same thing as a list comprehension |
| 2021-04-03 03:00:51 | <hololeap> | > [(x,y) | x <- [1,2,3], y <- [4,5,6]] |
| 2021-04-03 03:00:52 | <lambdabot> | [(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)] |
| 2021-04-03 03:01:03 | <Georgia> | I'm not very familiar with Haskell, which is why I cam here |
| 2021-04-03 03:01:26 | <Georgia> | I see |
| 2021-04-03 03:02:21 | <hololeap> | that function you're trying to understand is tricky because it is self-referencing |
| 2021-04-03 03:02:33 | <Georgia> | But we get t from the tails xs call, so rest is derived from that as well? |
| 2021-04-03 03:02:45 | <Georgia> | that and the recursive aspect are making it difficult for a beginner like myself |
| 2021-04-03 03:03:06 | <hololeap> | i had to run it to understand how it functioned :) |
| 2021-04-03 03:03:09 | × | Guest22848 quits (~finn_elij@gateway/tor-sasl/finnelija/x-67402716) (Ping timeout: 240 seconds) |
| 2021-04-03 03:03:21 | <hololeap> | so it might not be the best thing to start out with |
| 2021-04-03 03:03:39 | <Georgia> | It was part of a pretty simple iterative problem |
| 2021-04-03 03:04:23 | <Georgia> | The problem was to derive the minimum number of coins that could be used to make change given an amount and coin values |
| 2021-04-03 03:04:27 | × | hexfive quits (~hexfive@50.35.83.177) (Quit: i must go. my people need me.) |
| 2021-04-03 03:04:49 | <Georgia> | I tried using DP and found this solution, which is when I showed up here :p |
| 2021-04-03 03:05:06 | → | gnumonic joins (~gnumonic@c-73-170-91-210.hsd1.ca.comcast.net) |
| 2021-04-03 03:05:22 | <hololeap> | what is DP? |
| 2021-04-03 03:05:26 | <Georgia> | dynamic programming |
| 2021-04-03 03:05:55 | → | abhixec joins (~abhixec@c-67-169-139-16.hsd1.ca.comcast.net) |
| 2021-04-03 03:06:19 | <Georgia> | when you say it's self referencing do you mean the recursion? |
| 2021-04-03 03:07:13 | × | conal quits (~conal@64.71.133.70) (Quit: Computer has gone to sleep.) |
| 2021-04-03 03:08:26 | → | dsrt^ joins (dsrt@ip98-184-89-2.mc.at.cox.net) |
| 2021-04-03 03:08:35 | → | conal joins (~conal@64.71.133.70) |
| 2021-04-03 03:09:02 | <hololeap> | right, it calls `rest` from inside the definition of `rest` |
| 2021-04-03 03:09:31 | <hololeap> | and it's leveraging the list monad, so it's kind of hard to grok |
| 2021-04-03 03:09:32 | <Georgia> | did you mean draw from draw? |
| 2021-04-03 03:09:42 | <hololeap> | sorry, yes i did mean that |
| 2021-04-03 03:09:45 | <Georgia> | all good |
| 2021-04-03 03:09:52 | <Georgia> | which part is "the list monad" |
| 2021-04-03 03:10:03 | <Georgia> | I have to be honest and say I don't grok monads at all yet |
| 2021-04-03 03:10:59 | <Georgia> | also at the base case of n = 0, we see that draw returns an empty array |
| 2021-04-03 03:11:12 | <Georgia> | so nothing gets appended to the t0 at that point? |
| 2021-04-03 03:11:43 | <hololeap> | t0 doesn't even get named in that case. it just returns [[]] |
| 2021-04-03 03:12:10 | <Georgia> | Ah I meant in the case before it |
| 2021-04-03 03:12:18 | <hololeap> | the list monad can combine elements of multiple lists and it behaves like a cartesian product |
| 2021-04-03 03:12:32 | <Georgia> | inside of the list comprehension, we end once draw t (n-1) is called with n = 1 |
| 2021-04-03 03:12:36 | <hololeap> | for instance, earlier i gave the example of [(x,y) | x <- [1,2,3], y <- [4,5,6]] |
| 2021-04-03 03:13:07 | <hololeap> | but i don't have to use (x,y) there, i could use any function on x and y and it would behave the way you would expect |
| 2021-04-03 03:13:10 | <Georgia> | but there is some `tails xs` related to it right |
| 2021-04-03 03:13:12 | <Georgia> | mhm |
| 2021-04-03 03:13:52 | <hololeap> | in this case, the second list is computed from `draw xs (n-1)` |
All times are in UTC.