Logs: freenode/#haskell
| 2021-03-20 19:00:38 | → | ezrakilty joins (~ezrakilty@97-113-58-224.tukw.qwest.net) |
| 2021-03-20 19:01:20 | → | Vadrigar joins (~Vadrigar@ip5b417208.dynamic.kabel-deutschland.de) |
| 2021-03-20 19:01:27 | → | frozenErebus joins (~frozenEre@94.129.70.18) |
| 2021-03-20 19:01:28 | × | RandomArcher quits (~isho@90.153.145.61) (Ping timeout: 276 seconds) |
| 2021-03-20 19:02:26 | × | berberman_ quits (~berberman@unaffiliated/berberman) (Ping timeout: 244 seconds) |
| 2021-03-20 19:03:23 | hackage | place-cursor-at 1.0.1 - A utility for X11 that moves the mouse cursor using the keyboard https://hackage.haskell.org/package/place-cursor-at-1.0.1 (unclechu) |
| 2021-03-20 19:03:35 | → | berberman joins (~berberman@unaffiliated/berberman) |
| 2021-03-20 19:04:57 | → | mikoto-chan joins (~anass@gateway/tor-sasl/mikoto-chan) |
| 2021-03-20 19:05:45 | × | Vadrigar quits (~Vadrigar@ip5b417208.dynamic.kabel-deutschland.de) (Ping timeout: 256 seconds) |
| 2021-03-20 19:06:53 | hackage | HTTP 4000.3.16 - A library for client-side HTTP https://hackage.haskell.org/package/HTTP-4000.3.16 (GaneshSittampalam) |
| 2021-03-20 19:06:53 | × | emmanuel_erc quits (~user@2603-7000-9600-01c9-0000-0000-0000-0874.res6.spectrum.com) (Read error: Connection reset by peer) |
| 2021-03-20 19:07:02 | → | emmanuel_erc joins (~user@2603-7000-9600-01c9-0000-0000-0000-0874.res6.spectrum.com) |
| 2021-03-20 19:10:45 | × | Rudd0 quits (~Rudd0@185.189.115.103) (Ping timeout: 264 seconds) |
| 2021-03-20 19:11:15 | × | ajc quits (~ajc@69.231.232.79) (Remote host closed the connection) |
| 2021-03-20 19:12:29 | → | Mrbuck joins (~Mrbuck@gateway/tor-sasl/mrbuck) |
| 2021-03-20 19:12:40 | → | tempate joins (~tempate@unaffiliated/tempate) |
| 2021-03-20 19:13:24 | <gentauro> | this `ghc-vis` is kind of amazing :o https://www.youtube.com/watch?v=mDzg-e3OSz8 |
| 2021-03-20 19:14:27 | → | Benzi-Junior joins (~BenziJuni@88-149-67-143.du.xdsl.is) |
| 2021-03-20 19:16:09 | × | kenran quits (~kenran@mue-88-130-62-114.dsl.tropolys.de) (Ping timeout: 264 seconds) |
| 2021-03-20 19:17:10 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2021-03-20 19:17:35 | × | conal quits (~conal@64.71.133.70) (Quit: Computer has gone to sleep.) |
| 2021-03-20 19:17:56 | → | kenran joins (~kenran@i59F67B31.versanet.de) |
| 2021-03-20 19:18:43 | → | conal joins (~conal@64.71.133.70) |
| 2021-03-20 19:19:22 | → | knupfer joins (~Thunderbi@i5E86B4F3.versanet.de) |
| 2021-03-20 19:20:21 | → | ajc joins (~ajc@69.231.232.79) |
| 2021-03-20 19:21:45 | → | kam1 joins (~kam1@83.123.237.152) |
| 2021-03-20 19:21:51 | Moyst_ | is now known as Moyst |
| 2021-03-20 19:22:23 | × | kam1 quits (~kam1@83.123.237.152) (Read error: Connection reset by peer) |
| 2021-03-20 19:22:23 | × | emmanuel_erc quits (~user@2603-7000-9600-01c9-0000-0000-0000-0874.res6.spectrum.com) (Read error: Connection reset by peer) |
| 2021-03-20 19:22:37 | → | emmanuel_erc joins (~user@2603-7000-9600-01c9-0000-0000-0000-0874.res6.spectrum.com) |
| 2021-03-20 19:24:32 | → | heatsink joins (~heatsink@2600:1700:bef1:5e10:6075:d116:7f4b:9342) |
| 2021-03-20 19:25:34 | × | zebrag quits (~inkbottle@aaubervilliers-654-1-109-157.w86-212.abo.wanadoo.fr) (Quit: Konversation terminated!) |
| 2021-03-20 19:25:53 | → | zebrag joins (~inkbottle@aaubervilliers-654-1-109-157.w86-212.abo.wanadoo.fr) |
| 2021-03-20 19:25:59 | <tempate> | Hello there. This is my very first Haskell program: https://paste.tomsmeding.com/tbitwLuL . It's from Advent of Code 2020, day 1. It would be great if I could get some feedback on what to improve and how to do things in a more haskellian way. |
| 2021-03-20 19:26:31 | → | elliott__ joins (~elliott@pool-108-51-101-42.washdc.fios.verizon.net) |
| 2021-03-20 19:27:24 | × | ajc quits (~ajc@69.231.232.79) (Remote host closed the connection) |
| 2021-03-20 19:28:10 | <ski> | tempate : use guards instead of `if'-`then'-`else' ? |
| 2021-03-20 19:28:53 | <ski> | personally, i would definitely remove all `$'s, except maybe the ones directly after `putStrLn' |
| 2021-03-20 19:29:22 | <tempate> | ski: oh, right, guards seem reasonable |
| 2021-03-20 19:29:30 | <tomsmeding> | tempate: kind of unrelated to the programming language, but I believe your 'star1' is quadratic in the length of the input list, and 'star2' is cubic |
| 2021-03-20 19:29:33 | <ski> | (brackets are nothing to be afraid of. and `(map read $ lines contents)' doesn't even have less brackets than `map read (lines contents)') |
| 2021-03-20 19:29:38 | <tempate> | ski: may I ask why would you remove all the $s? |
| 2021-03-20 19:29:41 | <tomsmeding> | there are faster algorithms :) |
| 2021-03-20 19:29:50 | <ski> | tempate : because they look ugly, imho |
| 2021-03-20 19:30:29 | <ski> | (and, for newbies, may indicate thinking that "avoiding brackets" is something to strive for, in itself) |
| 2021-03-20 19:30:31 | <tempate> | tomsmeding: yes, I'm aware. I was trying to get a very simple version in to see how I did. |
| 2021-03-20 19:31:25 | <tempate> | I've been told that in Haskell it's usually idiomatic to use small names, so would it be better to replace (first:numbers) with (x:xs), for instance? |
| 2021-03-20 19:31:28 | → | Lord_of_Life_ joins (~Lord@unaffiliated/lord-of-life/x-0885362) |
| 2021-03-20 19:31:56 | <ski> | tempate : instead of `/= Nothing', better to use pattern-matching (or `isJust'/`isNothing', if you must) |
| 2021-03-20 19:33:04 | × | fendor quits (~fendor@178.115.129.42.wireless.dyn.drei.com) (Remote host closed the connection) |
| 2021-03-20 19:33:05 | <ski> | tempate : reasonable length of names depend on the scope of the names, and also on how general they are. e.g. `object' or `value' isn't really any better than `x' |
| 2021-03-20 19:33:24 | → | LKoen joins (~LKoen@194.250.88.92.rev.sfr.net) |
| 2021-03-20 19:33:55 | <ski> | for numbers, at least integers, i'd commonly use `n' or `m' |
| 2021-03-20 19:34:06 | × | Lord_of_Life quits (~Lord@unaffiliated/lord-of-life/x-0885362) (Ping timeout: 246 seconds) |
| 2021-03-20 19:34:23 | × | emmanuel_erc quits (~user@2603-7000-9600-01c9-0000-0000-0000-0874.res6.spectrum.com) (Read error: Connection reset by peer) |
| 2021-03-20 19:34:26 | Lord_of_Life_ | is now known as Lord_of_Life |
| 2021-03-20 19:34:44 | <ski> | it's possible to replace the type ascription in the definition of `numbers' in `main', with a type signature, if you'd prefer that |
| 2021-03-20 19:35:15 | <ski> | `star2' doesn't handle the empty list. is that intended ? |
| 2021-03-20 19:35:34 | × | heatsink quits (~heatsink@2600:1700:bef1:5e10:6075:d116:7f4b:9342) (Remote host closed the connection) |
| 2021-03-20 19:36:24 | <ski> | (usually, if reasonable, it's better to allow trivial/vacuous/dummy/null cases. can be more flexible, may lead to more laws to refactor and reason with. can improve DRY) |
| 2021-03-20 19:36:55 | → | bitmapper joins (uid464869@gateway/web/irccloud.com/x-xsbczufuwcygdtaj) |
| 2021-03-20 19:37:29 | <ski> | seeing `fromJust' (and similar partial functions) is usually a code smell |
| 2021-03-20 19:37:48 | <tomsmeding> | % star1' numbers target = listToMaybe [x * (target - x) | x:xs <- tails numbers, target - x `elem` xs] |
| 2021-03-20 19:37:48 | <yahb> | tomsmeding: |
| 2021-03-20 19:38:00 | <tomsmeding> | % star1' [1,5,3,4,2,3,4,3] 5 |
| 2021-03-20 19:38:00 | <yahb> | tomsmeding: Just 4 |
| 2021-03-20 19:38:06 | <tomsmeding> | % 1 * 4 |
| 2021-03-20 19:38:06 | <yahb> | tomsmeding: 4 |
| 2021-03-20 19:38:14 | <tomsmeding> | well it's shorter :p |
| 2021-03-20 19:38:20 | <ski> | `x:xs <- tails numbers' is a nice trick :) |
| 2021-03-20 19:38:52 | <tomsmeding> | yes I was messing around with `zip numbers (tail (tails numbers))` but then I was like, wait, there was this trick :) |
| 2021-03-20 19:39:11 | <tempate> | Alright, how is this for version 2: https://paste.tomsmeding.com/1kzTAk3u ? |
| 2021-03-20 19:39:15 | → | fendor joins (~fendor@178.115.129.42.wireless.dyn.drei.com) |
| 2021-03-20 19:39:51 | <tomsmeding> | tempate: I find your second version quite a bit more readable than the first |
| 2021-03-20 19:40:05 | ski | concurs |
| 2021-03-20 19:40:26 | <tempate> | ski: oh, right, I didn't consider the empty list in star2 'cus it'll never happen |
| 2021-03-20 19:40:28 | <ski> | (oh, i'd write `IO ()', i suppose) |
| 2021-03-20 19:40:46 | <tempate> | oh, ok |
| 2021-03-20 19:40:51 | <ski> | > lines "" |
| 2021-03-20 19:40:53 | <lambdabot> | [] |
| 2021-03-20 19:41:08 | <ski> | it would happen, with empty standard input |
| 2021-03-20 19:41:35 | × | cyphase quits (~cyphase@unaffiliated/cyphase) (Quit: cyphase.com) |
| 2021-03-20 19:41:49 | <tempate> | I know this is trivial, but should I handle the empty list before or after the non-trivial case? |
| 2021-03-20 19:41:59 | <ski> | (perhaps there's a precondition in the task that that won't happen) |
| 2021-03-20 19:42:18 | <ski> | i usually handle the empty case, or base case(s), first |
| 2021-03-20 19:42:34 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-03-20 19:42:37 | <ski> | they're commonly shorter than the recursive case(s) |
| 2021-03-20 19:43:20 | <tempate> | Alright |
| 2021-03-20 19:43:32 | <tomsmeding> | gentauro: fancy! |
| 2021-03-20 19:43:39 | <ski> | if you want to think of the recursion as effecting a kind of loop, then what you're doing here is more akin to a `while' loop anyway, and in that case the termination condition is also upfront |
| 2021-03-20 19:44:21 | × | Pickchea quits (~private@unaffiliated/pickchea) (Ping timeout: 264 seconds) |
| 2021-03-20 19:44:26 | <ski> | (sometimes people put the base case last, i guess because they think of it as "this will happen last, at the end of the list". however, e.g. for trees, there's no single "end", there's many leaves) |
| 2021-03-20 19:44:39 | <ski> | @src zip |
| 2021-03-20 19:44:39 | <lambdabot> | zip (a:as) (b:bs) = (a,b) : zip as bs |
| 2021-03-20 19:44:39 | <lambdabot> | zip _ _ = [] |
| 2021-03-20 19:45:32 | <ski> | is an example where the base case is last, because here the ordering actually matters, due to the defining equations having overlapping definienda, and Haskell picking the first one that matches |
| 2021-03-20 19:45:49 | <tempate> | Hmmm |
| 2021-03-20 19:45:50 | <ski> | (that is a debatable choice, but it's now how Haskell works) |
| 2021-03-20 19:45:53 | × | remal quits (~remal@d24-57-234-201.home.cgocable.net) (Ping timeout: 245 seconds) |
| 2021-03-20 19:46:16 | → | ft joins (~ft@shell.chaostreff-dortmund.de) |
All times are in UTC.