Logs: freenode/#haskell
| 2021-04-30 01:43:50 | <monochrom> | So the example there begins with having "data S = MkS{x::Int}" and "data T = MkT{x::NotInt}". |
| 2021-04-30 01:44:06 | × | CrazyPython quits (~crazypyth@98.122.164.118) (Ping timeout: 240 seconds) |
| 2021-04-30 01:44:12 | <monochrom> | If you say "ok2 :: S->Int; ok2 = x" it's fine. |
| 2021-04-30 01:44:32 | <monochrom> | Then if you say "bad :: S->Int; bad s = x s" it is not good enough. |
| 2021-04-30 01:44:56 | <monochrom> | That's right, eta makes a difference. |
| 2021-04-30 01:46:39 | → | nineonine joins (~nineonine@50.216.62.2) |
| 2021-04-30 01:48:06 | <monochrom> | "bad" can be fixed by: "ok4 s = x (s :: S)" |
| 2021-04-30 01:48:46 | → | CrazyPython joins (~crazypyth@98.122.164.118) |
| 2021-04-30 01:50:08 | → | ddellacosta joins (~ddellacos@86.106.143.203) |
| 2021-04-30 01:53:05 | <zzz> | i personally avoid record extensions and favor something like the convention: data Person = Person { personName :: String , personAge :: Int } |
| 2021-04-30 01:53:29 | <zzz> | RecordWildCards is specially evil |
| 2021-04-30 01:53:44 | <jackdk> | so would I but I am writing a PR to a library and don't want to rearrange the whole interface |
| 2021-04-30 01:54:12 | × | ddellacosta quits (~ddellacos@86.106.143.203) (Ping timeout: 240 seconds) |
| 2021-04-30 01:55:28 | <Cale> | I hate DuplicateRecordFields, I wish we could just get rid of it -- all the extensions around records lately have been pretty bad. |
| 2021-04-30 01:56:02 | <sm[m]> | zzz: I do the same but usually abbreviate the prefix, Person -> p etc. |
| 2021-04-30 01:56:24 | <Cale> | Where I work, we use the convention _typeName_fieldName |
| 2021-04-30 01:56:36 | × | Neuromancer quits (~Neuromanc@unaffiliated/neuromancer) (Ping timeout: 260 seconds) |
| 2021-04-30 01:56:51 | <Cale> | (and then if there's a lens, it lacks the initial underscore, but we only make lenses if we need to) |
| 2021-04-30 01:56:58 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 252 seconds) |
| 2021-04-30 01:57:13 | <Cale> | It's honestly fine, haha |
| 2021-04-30 01:57:49 | <sm[m]> | woah, that's long |
| 2021-04-30 01:59:16 | <Cale> | Yeah, my initial reaction was that I didn't like it very much, but having gotten used to it, it's kind of nice in some ways |
| 2021-04-30 01:59:59 | → | Alleria joins (~textual@2603-7000-3040-0000-159e-3a17-d3d5-238e.res6.spectrum.com) |
| 2021-04-30 02:00:18 | <zzz> | Cale: why is that better than (fieldName typeName) ? |
| 2021-04-30 02:00:24 | Alleria | is now known as Guest71082 |
| 2021-04-30 02:00:32 | <Cale> | zzz: identifiers can't have spaces in them |
| 2021-04-30 02:00:34 | <zzz> | ignore that |
| 2021-04-30 02:00:57 | <Cale> | I just mean we name our record fields for a type called TypeName with the prefix _typeName_ |
| 2021-04-30 02:01:57 | <zzz> | got it. i forgot what the context of this conversation was for a second |
| 2021-04-30 02:02:36 | <zzz> | existential middle of the night Haskell question: are case expressions useful? |
| 2021-04-30 02:02:39 | <Cale> | You never have to think very hard about what the fields will be called, and if you have tags/completion, that's quite useful |
| 2021-04-30 02:02:54 | <Cale> | Uh, of course they are, they're fundamental |
| 2021-04-30 02:03:08 | <zzz> | why? |
| 2021-04-30 02:03:09 | → | falafel joins (~falafel@pool-96-255-70-50.washdc.fios.verizon.net) |
| 2021-04-30 02:03:15 | × | juliagoda quits (~juliagoda@2a02:a31a:e13a:eb00:758f:d455:b475:46e4) (Quit: Leaving) |
| 2021-04-30 02:03:18 | × | CrazyPython quits (~crazypyth@98.122.164.118) (Read error: Connection reset by peer) |
| 2021-04-30 02:03:19 | <Cale> | At some level, if you never pattern matched on anything, there would never be any reason to evaluate any expressions. |
| 2021-04-30 02:04:15 | → | pavonia joins (~user@unaffiliated/siracusa) |
| 2021-04-30 02:05:07 | × | Guest71082 quits (~textual@2603-7000-3040-0000-159e-3a17-d3d5-238e.res6.spectrum.com) (Ping timeout: 276 seconds) |
| 2021-04-30 02:05:30 | <zzz> | i mean from the syntax perspective, aren't they interchangeable with guards? |
| 2021-04-30 02:05:30 | × | nicholasbulka quits (~nicholasb@2601:900:4301:da0:f09e:8831:6f30:999f) (Remote host closed the connection) |
| 2021-04-30 02:05:50 | → | olligobber joins (olligobber@gateway/vpn/privateinternetaccess/olligobber) |
| 2021-04-30 02:05:54 | <Cale> | You mean with multiple equations for a function definition? |
| 2021-04-30 02:06:01 | <zzz> | yes |
| 2021-04-30 02:06:28 | <Cale> | Well, if you don't mind naming additional functions, you could get by with just that. |
| 2021-04-30 02:06:34 | → | nicholasbulka joins (~nicholasb@2601:900:4301:da0:5440:6bb8:f181:7832) |
| 2021-04-30 02:06:53 | <Cale> | But honestly, these days I pretty strongly avoid repeating the name of my function n times |
| 2021-04-30 02:07:32 | <Cale> | (when I can, at least) |
| 2021-04-30 02:08:13 | <Cale> | Really, that syntax gets translated into case expressions |
| 2021-04-30 02:08:30 | <zzz> | you dont need to repeat it, just add: | Value <- something |
| 2021-04-30 02:08:50 | <Cale> | Oh, pattern guards |
| 2021-04-30 02:08:56 | <jackdk> | It is a common error to use guards where cases will do |
| 2021-04-30 02:09:06 | <zzz> | why is that? |
| 2021-04-30 02:09:24 | × | urodna quits (~urodna@unaffiliated/urodna) (Quit: urodna) |
| 2021-04-30 02:09:47 | <Cale> | I'd only consider it strange if you're doing stuff like | not (null xs) |
| 2021-04-30 02:09:55 | <Cale> | rather than just pattern matching |
| 2021-04-30 02:10:23 | <Cale> | It is a little unusual to make extensive use of pattern guards though |
| 2021-04-30 02:11:17 | <Cale> | But yeah, these syntaxes are definitely interconvertible |
| 2021-04-30 02:11:18 | × | werneta quits (~werneta@70-142-214-115.lightspeed.irvnca.sbcglobal.net) (Remote host closed the connection) |
| 2021-04-30 02:11:37 | × | nicholasbulka quits (~nicholasb@2601:900:4301:da0:5440:6bb8:f181:7832) (Ping timeout: 276 seconds) |
| 2021-04-30 02:11:44 | <Axman6> | it's hard to understate how fundamental case statements are in Haskell, they are literally the way things are evaluated. Almost everything else that seems case-y is just case sugar |
| 2021-04-30 02:11:52 | × | horatiohb quits (~horatiohb@159.203.87.174) (Ping timeout: 240 seconds) |
| 2021-04-30 02:11:59 | <Cale> | Note also that guards are part of the syntax of case expressions |
| 2021-04-30 02:12:06 | <c_wraith> | that's not quite true. let is sort of the opposite of case |
| 2021-04-30 02:12:07 | <Cale> | (though they are sugar) |
| 2021-04-30 02:13:16 | <Cale> | c_wraith: Yeah, you can always define a new function which does the pattern matching, but you're then somewhat relying on the compiler to inline it I suppose. |
| 2021-04-30 02:14:37 | <Cale> | Once you get rid of enough of the sugar, it's possible to think of case as being the primary way that the stack is managed, and let as being the primary way that the heap is managed |
| 2021-04-30 02:14:39 | <zzz> | i hate case expressions. must be some childhood traume. i avoid them in every language |
| 2021-04-30 02:14:56 | <Cale> | case expressions in Haskell are not much like case expressions in most languages |
| 2021-04-30 02:14:57 | Axman6 | https://imgflip.com/i/57orv1 |
| 2021-04-30 02:15:04 | <Cale> | Except if you're thinking of like ML, or something |
| 2021-04-30 02:15:47 | <Axman6> | yeah, case is not switch in other languages |
| 2021-04-30 02:16:34 | → | slewis joins (~slewis@217.146.82.202) |
| 2021-04-30 02:16:46 | <zzz> | i do like LambdaCase though i dont remembet the last time i've used it |
| 2021-04-30 02:17:00 | → | minoru_shiraeesh joins (~shiraeesh@5.101.59.47) |
| 2021-04-30 02:17:36 | <Cale> | In Haskell, entering a function doesn't put anything on the stack (unless the function wasn't yet a lambda, but that's kind of the rarer case), but entering a case expression does: you put the case expression on the stack while the scrutinee gets evaluated |
| 2021-04-30 02:18:42 | <Cale> | If you're thinking at a kind of low level, it becomes natural to write out the case expressions as you'd expect them to exist in Core -- they might get mangled a bit along the way, but it can still be helpful if you're trying to think operationally about how things are going to perform. |
| 2021-04-30 02:18:53 | <Axman6> | I don;t even know how to write Haskell without using case, like, everywhere. it's so fundamental to programming in the language. our current code base seems to have nearly 8.5k case statements |
| 2021-04-30 02:19:17 | <Cale> | Yeah, we use case everywhere as well. |
| 2021-04-30 02:19:21 | <Axman6> | (searching using the regex "(\W|\\)case\W") |
| 2021-04-30 02:19:41 | <c_wraith> | honestly, sometimes I use case on Bool |
| 2021-04-30 02:19:59 | <Axman6> | yeah, I always feel weird using if |
| 2021-04-30 02:20:42 | <Cale> | Yeah, I'm not sure I'd ever be pro-removing-if-from-Haskell, but it's a somewhat reasonable position. |
| 2021-04-30 02:20:45 | <zzz> | behold: https://paste.jrvieira.com/1619749235361 |
| 2021-04-30 02:21:10 | ← | jao parts (~jao@pdpc/supporter/professional/jao) () |
| 2021-04-30 02:21:32 | <Cale> | Why 1 <- c rather than c == 1 ? |
| 2021-04-30 02:21:50 | → | thunderrd joins (~thunderrd@183.182.115.196) |
| 2021-04-30 02:22:00 | × | stree quits (~stree@68.36.8.116) (Ping timeout: 268 seconds) |
| 2021-04-30 02:22:18 | <zzz> | style? dunno |
| 2021-04-30 02:22:53 | <zzz> | i find it easier to read |
| 2021-04-30 02:23:07 | <zzz> | or found it, in that case |
| 2021-04-30 02:23:08 | <Cale> | You could also remove a lot of the repeated mentions of c and just have a case c of |
| 2021-04-30 02:23:09 | <Axman6> | if this were my code, I'd align the ='s toi make the pattern distinct from the result, but that's jujst me. I like vertical alignment, it makes my dyslexia less problematic |
| 2021-04-30 02:23:52 | <Axman6> | yeah step is crying out to be a case statement |
| 2021-04-30 02:24:09 | → | pfurla_ joins (~pfurla@ool-182ed2e2.dyn.optonline.net) |
| 2021-04-30 02:24:11 | <zzz> | Axman6: i tend to agree but that was written in a hurry. that's the intcode mchine from AOC'19 |
| 2021-04-30 02:24:11 | <Axman6> | with guards when there's extra checks necessary |
| 2021-04-30 02:24:18 | <Cale> | (or case expression) |
| 2021-04-30 02:25:02 | <zzz> | the goal of showing you this mess was to entertain you |
| 2021-04-30 02:25:30 | <Cale> | It's not the worst, but yeah, there are other options |
All times are in UTC.