Logs: freenode/#haskell
| 2020-09-26 17:57:51 | × | poljar quits (~poljar@93-139-70-179.adsl.net.t-com.hr) (Remote host closed the connection) |
| 2020-09-26 17:58:10 | <nineonine> | it works fine up to 20 |
| 2020-09-26 17:58:18 | <nineonine> | after that it starts returning nonsense results |
| 2020-09-26 17:58:47 | → | poljar joins (~poljar@93-139-70-179.adsl.net.t-com.hr) |
| 2020-09-26 18:00:02 | × | rektide1 quits (~rektide@84.39.117.57) () |
| 2020-09-26 18:00:24 | <monochrom> | Could you post the complete code that produced -17.46... ? |
| 2020-09-26 18:00:27 | <monochrom> | @where paste |
| 2020-09-26 18:00:27 | <lambdabot> | Help us help you: please paste full code, input and/or output at eg https://paste.tomsmeding.com |
| 2020-09-26 18:00:57 | <nineonine> | here you go! |
| 2020-09-26 18:00:57 | <nineonine> | https://paste.tomsmeding.com/SDUUcLFg |
| 2020-09-26 18:01:00 | <nineonine> | thx! |
| 2020-09-26 18:01:29 | × | aplainzetakind quits (~johndoe@captainludd.powered.by.lunarbnc.net) (Quit: Free ZNC ~ Powered by LunarBNC: https://LunarBNC.net) |
| 2020-09-26 18:01:30 | → | laxask joins (~lax@unaffiliated/laxask) |
| 2020-09-26 18:01:38 | laxask | is now known as sudden |
| 2020-09-26 18:01:43 | <tomsmeding> | nineonine: the inner binomCoef takes Int's |
| 2020-09-26 18:01:49 | <tomsmeding> | that product [1..m] is going to overflow |
| 2020-09-26 18:01:54 | <nineonine> | aha |
| 2020-09-26 18:01:58 | × | mu_ quits (~mu@unaffiliated/mu) (Quit: mu_) |
| 2020-09-26 18:02:11 | <nineonine> | how do I fix it |
| 2020-09-26 18:02:14 | <monochrom> | > product [1..21] :: Int |
| 2020-09-26 18:02:16 | <lambdabot> | -4249290049419214848 |
| 2020-09-26 18:02:20 | <tomsmeding> | possible solutions: Integer instead of Int; Double instead of Int; use a different algorithm that isn't as susceptible to overflow :) |
| 2020-09-26 18:02:21 | <monochrom> | Ah, like that. |
| 2020-09-26 18:02:26 | <fluturel> | ski: are you still here? |
| 2020-09-26 18:02:38 | <ski> | no |
| 2020-09-26 18:02:46 | <ski> | i'm over there |
| 2020-09-26 18:02:46 | × | ap5 quits (~ap5@85.184.161.18) (Ping timeout: 256 seconds) |
| 2020-09-26 18:02:47 | <monochrom> | Yeah using factorial for binom is the worst idea. |
| 2020-09-26 18:02:53 | <fluturel> | i think i got it with pattern matching |
| 2020-09-26 18:02:56 | <monochrom> | In multiple ways, not just this one. |
| 2020-09-26 18:03:00 | <ski> | fluturel : okay ? |
| 2020-09-26 18:03:01 | <nineonine> | what would be a better solution here? |
| 2020-09-26 18:03:20 | <tomsmeding> | nineonine: e.g. https://math.stackexchange.com/a/927064/68044 |
| 2020-09-26 18:03:22 | <fluturel> | ski : you know, the zip' function |
| 2020-09-26 18:03:46 | <tomsmeding> | wait no |
| 2020-09-26 18:03:55 | <ski> | fluturel : yes, i didn't forget :) |
| 2020-09-26 18:04:24 | <ski> | (i meant "okay ?", as in "well, let's hear about it ?") |
| 2020-09-26 18:04:33 | → | adam_wespiser joins (~adam_wesp@209.6.42.110) |
| 2020-09-26 18:04:36 | <monochrom> | > product [1..21] :: Double |
| 2020-09-26 18:04:38 | <fluturel> | zip' :: [a] -> [b] -> [(a,b)] |
| 2020-09-26 18:04:38 | <lambdabot> | 5.109094217170944e19 |
| 2020-09-26 18:04:39 | <fluturel> | zip' (x:xs) (y:ys) = [(x,y)] ++ (zip' xs ys) |
| 2020-09-26 18:04:39 | <fluturel> | zip' _ [] = [] |
| 2020-09-26 18:04:39 | <fluturel> | zip' [] _ = [] |
| 2020-09-26 18:04:53 | <fluturel> | How do i post multiline code |
| 2020-09-26 18:05:14 | <geekosaur> | use a pastebin, ideally |
| 2020-09-26 18:05:27 | <geekosaur> | @where paste |
| 2020-09-26 18:05:28 | <lambdabot> | Help us help you: please paste full code, input and/or output at eg https://paste.tomsmeding.com |
| 2020-09-26 18:05:29 | → | aplainzetakind joins (~johndoe@captainludd.powered.by.lunarbnc.net) |
| 2020-09-26 18:05:55 | <dsal> | fluturel: You could also use ; |
| 2020-09-26 18:06:09 | × | rcdilorenzo quits (~rcdiloren@cpe-76-182-87-188.nc.res.rr.com) (Remote host closed the connection) |
| 2020-09-26 18:06:13 | <fluturel> | ski: https://pastebin.com/JLshNdsN |
| 2020-09-26 18:06:24 | <fluturel> | dsal: already made a pastebin, but thank you |
| 2020-09-26 18:06:53 | <dsal> | ; is helpful if you want lambdabot to run the code. :) |
| 2020-09-26 18:07:06 | → | snakemasterflex joins (~snakemast@213.100.206.23) |
| 2020-09-26 18:07:38 | <ski> | fluturel : yep, that looks fine :) |
| 2020-09-26 18:07:50 | <tomsmeding> | nineonine: https://codeforces.com/blog/entry/55311 that's the algorithm that I know, I can try functionalising it |
| 2020-09-26 18:07:50 | <fluturel> | ski: i vwas wondering if there is a better way to rewrite the last two lines. I mean,. they are the same thing, just in onecase the first list finishes its elements first |
| 2020-09-26 18:08:13 | → | chaosmasttter joins (~chaosmast@p200300c4a7105f0120adba39e14d4586.dip0.t-ipconnect.de) |
| 2020-09-26 18:08:16 | <ski> | fluturel : you could replace them with zip' _ _ = [] |
| 2020-09-26 18:08:19 | <fluturel> | or the other way around actually |
| 2020-09-26 18:08:29 | <ski> | as long as that defining equation is after the recursive one |
| 2020-09-26 18:08:33 | <nineonine> | tomsmeding, that would be great :) |
| 2020-09-26 18:09:04 | × | HarveyPwca quits (~HarveyPwc@c-98-220-98-201.hsd1.il.comcast.net) (Quit: Leaving) |
| 2020-09-26 18:09:12 | <ski> | fluturel : btw, the brackets around the recursive call are redundant. and you could use `:' in place of `++' |
| 2020-09-26 18:09:35 | <fluturel> | ski: actually yeah, you are right. If it doesn't match with the first pattern, the second will catch it regardless and return an empty list |
| 2020-09-26 18:09:44 | <fluturel> | ski: oh, didn't know that |
| 2020-09-26 18:10:11 | → | justanotheruser joins (~justanoth@unaffiliated/justanotheruser) |
| 2020-09-26 18:10:47 | <fluturel> | ski: just to clarify, which brackets? These: [(x,y)] ? |
| 2020-09-26 18:11:25 | × | snakemasterflex quits (~snakemast@213.100.206.23) (Ping timeout: 246 seconds) |
| 2020-09-26 18:11:27 | <ski> | fluturel : one argument for not replacing them like that would be that, the way you've written the defining equations, you could actually have them in any order. and you can understand them in isolation, as true statements about your function. but if you have the patterns in the base case overlap with the patterns in the recursive case, then you can't understand the base case in isolation |
| 2020-09-26 18:11:36 | <ski> | fluturel : no, the round brackets |
| 2020-09-26 18:11:39 | <dsal> | fluturel: (zip' xs ys) |
| 2020-09-26 18:11:53 | <ski> | ("around the recursive call") |
| 2020-09-26 18:11:55 | <dsal> | hlint will tell you things like that. |
| 2020-09-26 18:12:26 | <fluturel> | is hlint for emacs a thing? |
| 2020-09-26 18:12:32 | <dsal> | Just a cli tool |
| 2020-09-26 18:12:42 | <dsal> | But probably. |
| 2020-09-26 18:13:40 | → | acidjnk_new joins (~acidjnk@p200300d0c723789624d205acd1b15fd8.dip0.t-ipconnect.de) |
| 2020-09-26 18:13:58 | → | Saten-san joins (~Saten-san@ip-213-49-124-100.dsl.scarlet.be) |
| 2020-09-26 18:14:04 | <ski> | fluturel : .. but in some situations, one can replace a lot of extra cases, with just a single "catch-all"/"default" case, at the price of having overlapping cases |
| 2020-09-26 18:14:15 | <fluturel> | I am going to look more into defining the !!? operator and working with Maybe, as i have something to learn from there, but i think this is the more elegant solution. Not gonna lie, i feel quite proud of it :) |
| 2020-09-26 18:14:45 | <nineonine> | tomsmeding: btw, I used the solution from that SO answer and it seems to work fine. Many thanks again! |
| 2020-09-26 18:14:46 | <ski> | yes, this is the idiomatic solution |
| 2020-09-26 18:14:56 | <nineonine> | not SO, but SE |
| 2020-09-26 18:15:20 | <ski> | fluturel : i was just thinking that, doing it without explicit pattern-matching, could possibly be an interesting exercise |
| 2020-09-26 18:15:23 | <fluturel> | ski: i see what you mean, i guess for more complicated patterns, understanding them in isolation is better, but here overlapping them won't be such a burden for a reader |
| 2020-09-26 18:15:39 | <tomsmeding> | nineonine: yes it does seem to work fine indeed; I'm kind of surprised that it does though |
| 2020-09-26 18:15:40 | × | adam_wespiser quits (~adam_wesp@209.6.42.110) (Ping timeout: 272 seconds) |
| 2020-09-26 18:15:47 | <tomsmeding> | also, it contains non-tail recursion, while this one doesn't: https://paste.tomsmeding.com/cj6pnnXi |
| 2020-09-26 18:15:51 | <ski> | (btw, of course `!!' itself is defined, using pattern-matching. and the function you'd call from `!!?' also would be) |
| 2020-09-26 18:15:53 | <tomsmeding> | but feel free to use the SE one :p |
| 2020-09-26 18:16:00 | <nineonine> | will do, thx :D |
| 2020-09-26 18:16:13 | <tomsmeding> | (oh not choose2 but binomCoef of course) |
| 2020-09-26 18:16:27 | <nineonine> | I don't quite understand though why isn't it included in base |
| 2020-09-26 18:16:35 | <nineonine> | it seems somewhat useful sometimes |
| 2020-09-26 18:16:52 | <nineonine> | maybe because it is extremely inefficient? dunno |
| 2020-09-26 18:17:20 | <dsal> | base is too big. Things in base should be very useful all the time. |
| 2020-09-26 18:17:44 | <nineonine> | I agree |
| 2020-09-26 18:17:55 | <tomsmeding> | there is also not really a canonical implementation |
All times are in UTC.