Logs: freenode/#haskell
| 2020-11-21 01:30:52 | → | Tario joins (~Tario@201.192.165.173) |
| 2020-11-21 01:32:02 | <Ariakenom> | fubu: head takes the first element out of a list. while : adds an element to a list. so in x : (y : z) x is an element, y is an element, but z is a list. |
| 2020-11-21 01:32:27 | <Ariakenom> | so z shouldnt be an element, it should be a list |
| 2020-11-21 01:32:45 | × | nados quits (~dan@69-165-210-185.cable.teksavvy.com) (Ping timeout: 240 seconds) |
| 2020-11-21 01:33:56 | → | Lord_of_Life joins (~Lord@46.217.217.57) |
| 2020-11-21 01:34:22 | <Ariakenom> | z in my exanple is your (head $ zipWith (+) fibs2 (tail fibs2)) |
| 2020-11-21 01:34:56 | × | Lord_of_Life_ quits (~Lord@46.217.218.71) (Ping timeout: 240 seconds) |
| 2020-11-21 01:35:50 | × | LKoen quits (~LKoen@169.244.88.92.rev.sfr.net) (Quit: “It’s only logical. First you learn to talk, then you learn to think. Too bad it’s not the other way round.”) |
| 2020-11-21 01:38:21 | → | justanotheruser joins (~justanoth@unaffiliated/justanotheruser) |
| 2020-11-21 01:39:25 | <fubu> | thank you. I fixed the function, but now i'm failing to see how it works |
| 2020-11-21 01:39:30 | <fubu> | fibs2 = 1 : 1 : (zipWith (+) fibs2 (tail fibs2)) |
| 2020-11-21 01:40:04 | <fubu> | I kind of get it, but I don't see how the evaluation works in terms of what is on the stack at each point in time |
| 2020-11-21 01:41:03 | <dsal> | What's "the stack"? |
| 2020-11-21 01:41:07 | <Ariakenom> | you can do the step by step evaluation on paper |
| 2020-11-21 01:41:59 | <fubu> | hm, evaluation stack? |
| 2020-11-21 01:42:14 | × | conal quits (~conal@64.71.133.70) (Quit: Computer has gone to sleep.) |
| 2020-11-21 01:42:45 | <dsal> | That's a list, not a stack, though. Thinking of a stack will be rather confusing. |
| 2020-11-21 01:43:01 | <fubu> | i'm also not sure how the two instances of fibs2 on the right hand side are connected |
| 2020-11-21 01:43:08 | → | conal joins (~conal@64.71.133.70) |
| 2020-11-21 01:43:12 | <dsal> | zipWith does that. |
| 2020-11-21 01:43:13 | <dsal> | :t zipWith |
| 2020-11-21 01:43:14 | <lambdabot> | (a -> b -> c) -> [a] -> [b] -> [c] |
| 2020-11-21 01:43:14 | <fubu> | because i know if we do something like f x = g x x, then x only gets evaluated once |
| 2020-11-21 01:43:28 | <fubu> | oh yeah, i know how the terms are being added |
| 2020-11-21 01:43:38 | <fubu> | i'mi not too sure how it's getting evaluated though |
| 2020-11-21 01:43:52 | <fubu> | like you start with 1 : 1 : (zipWith (+) fibs2 (tail fibs2)) |
| 2020-11-21 01:44:08 | <fubu> | and then it calls the first fib2 on the RHS to evaluate it |
| 2020-11-21 01:44:14 | × | stree quits (~stree@50-108-97-52.adr01.mskg.mi.frontiernet.net) (Quit: Caught exception) |
| 2020-11-21 01:44:14 | × | star_cloud quits (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com) (Remote host closed the connection) |
| 2020-11-21 01:44:21 | <Ariakenom> | fubu, once or twice, like that, doesnt matter in this case |
| 2020-11-21 01:44:31 | → | stree joins (~stree@50-108-97-52.adr01.mskg.mi.frontiernet.net) |
| 2020-11-21 01:44:32 | <dsal> | > zipWith (+) [a, b, c, d] (tail [a, b, c, d]) :: [Expr] |
| 2020-11-21 01:44:34 | <lambdabot> | [a + b,b + c,c + d] |
| 2020-11-21 01:44:48 | <Ariakenom> | you can start with a simpler version |
| 2020-11-21 01:45:13 | × | raehik quits (~raehik@cpc95906-rdng25-2-0-cust156.15-3.cable.virginm.net) (Ping timeout: 260 seconds) |
| 2020-11-21 01:45:35 | → | kupi joins (uid212005@gateway/web/irccloud.com/x-vjlwewutkgmnxvxr) |
| 2020-11-21 01:45:40 | <Ariakenom> | nat = 0 : (map (+1) nat) |
| 2020-11-21 01:45:41 | → | star_cloud joins (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com) |
| 2020-11-21 01:45:45 | <dsal> | So once you get past the [1,1] at the beginning. It's just an infinite stream of numbers added to the same infinite stream of numbers after dropping the first one. |
| 2020-11-21 01:45:53 | <Ariakenom> | or even simpler |
| 2020-11-21 01:46:02 | <Ariakenom> | zeroes = 0: zeroes |
| 2020-11-21 01:46:14 | <fubu> | yeah i understand the nat case |
| 2020-11-21 01:46:51 | × | nbloomf quits (~nbloomf@2600:1700:ad14:3020:a4db:c497:ce73:79ee) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2020-11-21 01:47:13 | <dsal> | > let fibs2 = a : b : zipWith (+) fibs2 (tail fibs2) in fibs2 :: [Expr] |
| 2020-11-21 01:47:15 | <lambdabot> | [a,b,a + b,b + (a + b),a + b + (b + (a + b)),b + (a + b) + (a + b + (b + (a ... |
| 2020-11-21 01:47:47 | <dsal> | It's not super easy to think about that in terms of Peano numbers... |
| 2020-11-21 01:48:08 | <dsal> | > zipWith (+) [1..5] [2..6] |
| 2020-11-21 01:48:10 | <lambdabot> | [3,5,7,9,11] |
| 2020-11-21 01:48:32 | <dsal> | That's all it's doing. |
| 2020-11-21 01:48:41 | <fubu> | ok, i understand the zipWith now |
| 2020-11-21 01:48:52 | <fubu> | but what's the order in which things get evaluated? |
| 2020-11-21 01:48:57 | <fubu> | because at the first stage, you have something like |
| 2020-11-21 01:49:12 | <fubu> | 1 : 1 : (zipWith (+) [1,1,???] [1,???]) right |
| 2020-11-21 01:49:19 | <fubu> | where you only know the 1 : 1 exists |
| 2020-11-21 01:49:35 | <fubu> | so does it then lazily do the 1+1? |
| 2020-11-21 01:49:41 | <fubu> | and attach it to the list |
| 2020-11-21 01:49:45 | <fubu> | and then fill in the next step? |
| 2020-11-21 01:50:02 | <fubu> | and now it's 1 : 1 : (zipWith (+) [1, 1, 2, ...] [1, 2, ...] ) |
| 2020-11-21 01:50:46 | <Ariakenom> | well you know the first value of the two zipWith lists. so you know the first value of that result |
| 2020-11-21 01:51:15 | <fubu> | but isn't + lazy? |
| 2020-11-21 01:51:23 | <fubu> | so the result will be stored as 1+1 right |
| 2020-11-21 01:51:45 | <Ariakenom> | zipWith (+) [1,1,..] [1,..] = 2: zipWith (+) [1,..] [..] |
| 2020-11-21 01:51:58 | <Ariakenom> | fubu, sure |
| 2020-11-21 01:52:28 | <Ariakenom> | if you print (show) 1+1 then you will get the string "2" |
| 2020-11-21 01:52:54 | <dsal> | "stored" is kind of a weird word. I don't think it's "stored" anywhere. |
| 2020-11-21 01:52:59 | → | nbloomf joins (~nbloomf@2600:1700:ad14:3020:a4db:c497:ce73:79ee) |
| 2020-11-21 01:53:32 | <fubu> | how does the evaluation process work? |
| 2020-11-21 01:53:40 | <dsal> | > let fibs2 = a : b : zipWith (+) fibs2 (tail fibs2) in fibs2 :: [Expr] |
| 2020-11-21 01:53:43 | <lambdabot> | [a,b,a + b,b + (a + b),a + b + (b + (a + b)),b + (a + b) + (a + b + (b + (a ... |
| 2020-11-21 01:54:14 | <fubu> | like after compilation how does haskell know what order to do the lazy evaluation in? |
| 2020-11-21 01:54:46 | <dsal> | I'm not sure what you mean. There's a clear dependency. |
| 2020-11-21 01:55:00 | <Ariakenom> | the things that are computed are forced by main::IO () |
| 2020-11-21 01:55:19 | <fubu> | like |
| 2020-11-21 01:55:21 | <dsal> | Yeah, if you don't ever use the value, it's never computed, so it's not relevant. |
| 2020-11-21 01:55:42 | <fubu> | you have fibs2 = 1 : 1 : (zipWith (+) fibs2 (tail fibs2)) |
| 2020-11-21 01:55:55 | <fubu> | are all 3 fibs2 variables linked to each other |
| 2020-11-21 01:56:13 | <dsal> | > let fibs2 = 1 : 1 : (zipWith (+) fibs2 (tail fibs2)) in head fibs2 |
| 2020-11-21 01:56:15 | <lambdabot> | 1 |
| 2020-11-21 01:56:19 | <fubu> | so that when you compute a new value in fibs2, all 3 variables are automatically updated? |
| 2020-11-21 01:56:30 | <Ariakenom> | yeah, same variable |
| 2020-11-21 01:56:40 | <Ariakenom> | same memory object |
| 2020-11-21 01:57:17 | <dsal> | i.e., it's not a variable at all, and you're not so much computing values or updating things. It's just a list. |
| 2020-11-21 01:57:58 | <Ariakenom> | note that things are always updated from less information to more information. they dont change previous information |
| 2020-11-21 01:58:11 | <dsal> | > let as = 1 : 2 : 3 : as in take 11 as -- it just happens to include itself |
| 2020-11-21 01:58:12 | <lambdabot> | [1,2,3,1,2,3,1,2,3,1,2] |
| 2020-11-21 01:58:41 | <dsal> | But if you were to evaluate this concept manually without thinking about how you'd do it in C or something, it'd be pretty clear. |
| 2020-11-21 01:58:49 | → | falafel_ joins (~falafel@2601:547:1303:b30:7811:313f:d0f3:f9f4) |
| 2020-11-21 01:58:53 | <fubu> | ah yes, i come from C :P |
| 2020-11-21 01:59:13 | <dsal> | Dropping some of that baggage can be hard. :) |
| 2020-11-21 01:59:32 | <dsal> | You don't tell Haskell how to do things (mostly). You tell Haskell what you want done. |
| 2020-11-21 02:00:01 | <dsal> | You want a list that's made up of itself? You express it in the most simple way, and the runtime does the thing it could do to make that happen. |
| 2020-11-21 02:00:17 | <Ariakenom> | so (zeroes = 0: zeroes) the tail of the list actual is the same pointer as the beginning |
| 2020-11-21 02:00:17 | <dsal> | > let a = a in a -- of course, it has to at least make sense |
| 2020-11-21 02:00:21 | <lambdabot> | *Exception: <<loop>> |
| 2020-11-21 02:01:12 | × | wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 256 seconds) |
| 2020-11-21 02:01:15 | → | toorevitimirp joins (~tooreviti@117.182.180.118) |
| 2020-11-21 02:01:26 | <dsal> | But lists aren't necessarily slots of discrete values. They can just be an infinite recipe list for producing values. |
| 2020-11-21 02:01:33 | × | gxt quits (~gxt@gateway/tor-sasl/gxt) (Quit: WeeChat 2.9) |
| 2020-11-21 02:01:36 | <dsal> | > [ x^2 | x <- [1..] ] |
| 2020-11-21 02:01:38 | <lambdabot> | [1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484... |
All times are in UTC.