Logs: freenode/#haskell
| 2020-10-21 09:58:43 | <Echosolace> | From LYAH: The binary function is applied between the starting value and the head of the list. |
| 2020-10-21 09:59:04 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-10-21 09:59:13 | × | coot quits (~coot@37.30.49.255.nat.umts.dynamic.t-mobile.pl) (Remote host closed the connection) |
| 2020-10-21 09:59:15 | <Echosolace> | So foldl is applying this function to the head of the list: |
| 2020-10-21 09:59:16 | <Echosolace> | (\acc x -> if take nlen x == needle then True else acc |
| 2020-10-21 09:59:25 | <Echosolace> | ) |
| 2020-10-21 09:59:38 | <Echosolace> | is that correct? |
| 2020-10-21 10:00:01 | <ski> | Echosolace : not "binomial". you could say "binary", yes |
| 2020-10-21 10:00:09 | <Echosolace> | Oops |
| 2020-10-21 10:00:11 | <Echosolace> | Binary. |
| 2020-10-21 10:00:23 | → | coot joins (~coot@37.30.49.255.nat.umts.dynamic.t-mobile.pl) |
| 2020-10-21 10:00:27 | <ski> | yes, it's first applied to the initial accumulator, and the first element of the list. producing the next version of the accumulator |
| 2020-10-21 10:00:56 | <ski> | then it's applied again, to that accumulator, and the next element of the list, and so on. final version/value of the accumulator is the overall result |
| 2020-10-21 10:01:10 | → | Lord_of_Life_ joins (~Lord@46.217.218.115) |
| 2020-10-21 10:01:14 | → | dhil joins (~dhil@195.213.192.122) |
| 2020-10-21 10:01:27 | <Echosolace> | Ok... so at first the function is applied to the initial value of False? |
| 2020-10-21 10:01:29 | <ski> | (a binomial is a kind of polynomial) |
| 2020-10-21 10:01:41 | <ski> | yes |
| 2020-10-21 10:01:47 | <Echosolace> | Huh... ok. |
| 2020-10-21 10:02:06 | → | ffviewer joins (1bf6c255@27-246-194-85.adsl.fetnet.net) |
| 2020-10-21 10:02:46 | <ski> | take this example |
| 2020-10-21 10:02:55 | <Echosolace> | O god. |
| 2020-10-21 10:03:00 | <Echosolace> | Be gentle. |
| 2020-10-21 10:03:25 | <ski> | you can compare with the implementation of `foldl' |
| 2020-10-21 10:03:28 | <ski> | @src foldl |
| 2020-10-21 10:03:28 | <lambdabot> | foldl f z [] = z |
| 2020-10-21 10:03:28 | <lambdabot> | foldl f z (x:xs) = foldl f (f z x) xs |
| 2020-10-21 10:03:47 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 256 seconds) |
| 2020-10-21 10:04:06 | × | Lord_of_Life quits (~Lord@unaffiliated/lord-of-life/x-0885362) (Ping timeout: 246 seconds) |
| 2020-10-21 10:04:10 | Lord_of_Life_ | is now known as Lord_of_Life |
| 2020-10-21 10:04:19 | <ski> | and remember that `[2,3,5,7]' is syntactic sugar for `2:3:5:7:[]' (which means / is parsed as `2:(3:(5:(7:[])))', because `:' is specified as an "right-associative" infix operator) |
| 2020-10-21 10:04:37 | <Echosolace> | I got that last bit at least. |
| 2020-10-21 10:04:39 | <ski> | so, consider a definition like |
| 2020-10-21 10:04:50 | → | jamm_ joins (~jamm@unaffiliated/jamm) |
| 2020-10-21 10:04:50 | × | rprije quits (~rprije@110-175-117-18.tpgi.com.au) (Ping timeout: 256 seconds) |
| 2020-10-21 10:04:54 | × | jamm_ quits (~jamm@unaffiliated/jamm) (Remote host closed the connection) |
| 2020-10-21 10:04:56 | <ski> | sum = foldl (\acc n -> acc + n) 0 |
| 2020-10-21 10:05:01 | <ski> | which could even be abbreviated as |
| 2020-10-21 10:05:04 | × | Tario quits (~Tario@201.192.165.173) (Ping timeout: 256 seconds) |
| 2020-10-21 10:05:06 | <ski> | sum = foldl (+) 0 |
| 2020-10-21 10:05:16 | <ski> | now, the example |
| 2020-10-21 10:05:21 | <Echosolace> | Following. |
| 2020-10-21 10:05:34 | <ski> | sum [2,3,5,7] |
| 2020-10-21 10:05:45 | <ski> | = sum (2:3:5:7:[]) |
| 2020-10-21 10:05:54 | <ski> | = foldl (+) 0 (2:3:5:7:[]) |
| 2020-10-21 10:06:04 | × | zaquest quits (~notzaques@5.128.210.178) (Quit: Leaving) |
| 2020-10-21 10:06:08 | <ski> | = foldl (+) (0 + 2) (3:5:7:[]) |
| 2020-10-21 10:06:17 | → | Tario joins (~Tario@201.192.165.173) |
| 2020-10-21 10:06:23 | <ski> | = foldl (+) 2 (3:5:7:[]) |
| 2020-10-21 10:06:31 | <ski> | = foldl (+) (2 + 3) (5:7:[]) |
| 2020-10-21 10:06:33 | <Echosolace> | Then 2 + 3 and then the next iteration |
| 2020-10-21 10:06:35 | <Echosolace> | Yep |
| 2020-10-21 10:06:36 | <ski> | = foldl (+) 5 (5:7:[]) |
| 2020-10-21 10:06:43 | <ski> | = foldl (+) (5 + 5) (7:[]) |
| 2020-10-21 10:06:49 | <ski> | = foldl (+) 10 (7:[]) |
| 2020-10-21 10:06:56 | <ski> | = foldl (+) (10 + 7) [] |
| 2020-10-21 10:07:01 | <ski> | = foldl (+) 17 [] |
| 2020-10-21 10:07:04 | <ski> | = 17 |
| 2020-10-21 10:07:15 | → | zaquest joins (~notzaques@5.128.210.178) |
| 2020-10-21 10:07:20 | <Echosolace> | Thanks. Although what's tripping me up is involving False as the accumulator. |
| 2020-10-21 10:07:28 | <Echosolace> | (\acc x -> if take nlen x == needle then True else acc) |
| 2020-10-21 10:07:44 | <ski> | so, you're working your way, from the left to the right, combining the initial "seed" / accumulator, with one element at a time, until you've gone through them all |
| 2020-10-21 10:07:48 | <ski> | well |
| 2020-10-21 10:08:13 | <ski> | <ski> if `take nlen x == needle' is true, then we give `True', else we give `acc' |
| 2020-10-21 10:08:16 | <ski> | <ski> so `if take nlen x == needle then True else acc' is true if (and only if) ... ? (something about `take nlen x == needle' and `acc') |
| 2020-10-21 10:08:19 | <ski> | ski> Echosolace : can you fill in the "..." ? |
| 2020-10-21 10:08:58 | <Echosolace> | ? |
| 2020-10-21 10:09:05 | <Echosolace> | Oh |
| 2020-10-21 10:09:09 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-10-21 10:09:12 | <ski> | there is a relatively simple way to express it |
| 2020-10-21 10:09:30 | <Echosolace> | I know there's probably a better way to do it, but I'm trying to follow LYAH. |
| 2020-10-21 10:10:38 | × | arguapacha quits (~arguapach@bras-base-mtrlpq02hsy-grc-04-174-93-252-133.dsl.bell.ca) (Read error: Connection reset by peer) |
| 2020-10-21 10:10:59 | <ski> | well .. i was intending to try to show what happens with the accumulator, in your case |
| 2020-10-21 10:11:05 | → | arguapacha joins (~arguapach@bras-base-mtrlpq02hsy-grc-04-174-93-252-133.dsl.bell.ca) |
| 2020-10-21 10:11:13 | <Echosolace> | I think I am approaching an understanding. |
| 2020-10-21 10:11:19 | <ski> | but i think it's be easier to follow, with a more concise expression of the accumulating function |
| 2020-10-21 10:11:31 | × | waskell quits (~quassel@d66-183-124-7.bchsia.telus.net) (Read error: Connection reset by peer) |
| 2020-10-21 10:11:47 | → | waskell joins (~quassel@d66-183-124-7.bchsia.telus.net) |
| 2020-10-21 10:11:52 | <idnar> | does something like `[Async a] -> IO (Async a)` exist? |
| 2020-10-21 10:11:59 | <idnar> | err |
| 2020-10-21 10:12:08 | × | ambiso9 quits (~ambiso@209.182.239.205) (Quit: Ping timeout (120 seconds)) |
| 2020-10-21 10:12:14 | <idnar> | I mean `[Async a] -> IO (Async [a])` |
| 2020-10-21 10:12:26 | <ski> | you could still do the above "reduction/evaluation trace", for your `if'-`then'-`else' case .. but it'll be a little bit more cluttered |
| 2020-10-21 10:12:26 | → | ambiso9 joins (~ambiso@209.182.239.205) |
| 2020-10-21 10:12:46 | → | conal_ joins (~conal@ip-66-115-176-174.creativelink.net) |
| 2020-10-21 10:13:07 | <idnar> | `traverse wait` is close but I'd like to fail fast |
| 2020-10-21 10:13:16 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 246 seconds) |
| 2020-10-21 10:14:28 | × | conal quits (~conal@ip-66-115-176-174.creativelink.net) (Ping timeout: 256 seconds) |
| 2020-10-21 10:15:24 | Guest88073 | is now known as lep-delete |
| 2020-10-21 10:15:26 | lep-delete | is now known as Guest88073 |
| 2020-10-21 10:15:27 | Guest88073 | is now known as lep-delete |
| 2020-10-21 10:15:28 | lep-delete | is now known as Guest88073 |
| 2020-10-21 10:17:23 | <Echosolace> | Ok ok I think I've got it. My only wonder is why tails haystack gets called? |
| 2020-10-21 10:17:26 | <Echosolace> | in foldl (\acc x -> if take nlen x == needle then True else acc) False (tails haystack) |
| 2020-10-21 10:17:53 | <ski> | it produces a list of successive tails of the hay stack |
| 2020-10-21 10:17:57 | <merijn> | > tails [1..5] |
| 2020-10-21 10:17:59 | <lambdabot> | [[1,2,3,4,5],[2,3,4,5],[3,4,5],[4,5],[5],[]] |
| 2020-10-21 10:18:00 | → | nineonin_ joins (~textual@216-19-190-182.dyn.novuscom.net) |
| 2020-10-21 10:18:00 | <ski> | > tails "haystack" |
| 2020-10-21 10:18:04 | <lambdabot> | ["haystack","aystack","ystack","stack","tack","ack","ck","k",""] |
All times are in UTC.