Logs: freenode/#haskell
| 2021-03-16 14:23:50 | <dminuoso> | tomsmeding: Dont interpret them as guards, interpret them as "a wild guess at what a vertical bar could mean in the language" |
| 2021-03-16 14:23:51 | <tomsmeding> | different programming language with different syntax? |
| 2021-03-16 14:23:52 | <dminuoso> | :p |
| 2021-03-16 14:24:04 | <tomsmeding> | dminuoso: they said "thought that would act like a guard" :) |
| 2021-03-16 14:24:17 | <emetrusky> | this is my first time doing functional programming |
| 2021-03-16 14:24:29 | <tomsmeding> | welcome :) |
| 2021-03-16 14:24:35 | <emetrusky> | its v hard |
| 2021-03-16 14:24:52 | <tomsmeding> | but can also be rewarding |
| 2021-03-16 14:24:58 | <tomsmeding> | if you like the ideas |
| 2021-03-16 14:25:10 | <tomsmeding> | most people here do |
| 2021-03-16 14:25:14 | × | heatsink quits (~heatsink@2600:1700:bef1:5e10:7c0e:3b57:dfb:2cb4) (Ping timeout: 264 seconds) |
| 2021-03-16 14:25:51 | <dminuoso> | tomsmeding: I think they might not understand what a guard even is. |
| 2021-03-16 14:26:00 | <tomsmeding> | dminuoso: which is why I was asking :p |
| 2021-03-16 14:26:02 | <dminuoso> | Ah |
| 2021-03-16 14:26:07 | <emetrusky> | do what is guard lads? |
| 2021-03-16 14:26:16 | → | Stanley00 joins (~stanley00@unaffiliated/stanley00) |
| 2021-03-16 14:26:20 | <dminuoso> | emetrusky: are you familiar with functions in math defined as |
| 2021-03-16 14:26:24 | <emetrusky> | yes |
| 2021-03-16 14:27:01 | <dminuoso> | f(x) = x | x > 10 |
| 2021-03-16 14:27:02 | <dminuoso> | 2*x | otherwise |
| 2021-03-16 14:27:04 | <dminuoso> | Like this? |
| 2021-03-16 14:27:16 | → | idhugo__ joins (~idhugo@130.225.16.16) |
| 2021-03-16 14:27:25 | <dminuoso> | Perhaps in your country it might look a bit different. But this is a step-wise defined function. |
| 2021-03-16 14:27:30 | → | dbmikus joins (~dbmikus@cpe-76-167-86-219.natsow.res.rr.com) |
| 2021-03-16 14:27:37 | <dminuoso> | The pipe plus the thing to the right, that's what we'd call a guard in Haskell |
| 2021-03-16 14:27:51 | <dminuoso> | i.e. the `| x > 10` sort of "condition" is what we call a guard |
| 2021-03-16 14:28:05 | <emetrusky> | so a guard is like an if statement |
| 2021-03-16 14:28:19 | <dminuoso> | It's kind of related, I guess |
| 2021-03-16 14:28:23 | <tomsmeding> | Different notation: |
| 2021-03-16 14:28:23 | <tomsmeding> | f(x) = / x, x > 10, |
| 2021-03-16 14:28:23 | <tomsmeding> | \ 2*x, otherwise |
| 2021-03-16 14:28:33 | <tomsmeding> | oh bummer alignment fails |
| 2021-03-16 14:28:46 | <tomsmeding> | anyway multiple lines preceded by a large { |
| 2021-03-16 14:29:42 | <dminuoso> | emetrusky: In Haskell, however, we place the guard on the left side of the equals sign. |
| 2021-03-16 14:29:46 | <dminuoso> | So the Haskell equivalent of the above is: |
| 2021-03-16 14:29:50 | <dminuoso> | f x | x > 10 = x |
| 2021-03-16 14:29:52 | <dminuoso> | | otherwise = 2 * x |
| 2021-03-16 14:29:57 | × | idhugo_ quits (~idhugo@87-49-147-45-mobile.dk.customer.tdc.net) (Ping timeout: 264 seconds) |
| 2021-03-16 14:30:09 | <tomsmeding> | which can also be written using an if-then-else expression as: f x = if x > 10 then x else 2 * x |
| 2021-03-16 14:30:24 | <emetrusky> | oh ok thanks very much i think i have got a bit better understanding |
| 2021-03-16 14:30:35 | <dminuoso> | So these are sort of separate "branches" a function can take. When the function is applied, each guard is tested from top to bottom, the first definition where the guard evaluates to True in the guard is then taken |
| 2021-03-16 14:30:57 | <ADG1089__> | can anyone help with https://github.com/haskell/cabal/issues/7325 |
| 2021-03-16 14:31:02 | × | rj_ quits (~x@gateway/tor-sasl/rj) (Ping timeout: 268 seconds) |
| 2021-03-16 14:31:06 | <dminuoso> | (If you read this carefully, you might notice that this implies that `otherwise` must evaluate to True |
| 2021-03-16 14:31:18 | <dminuoso> | And it turns out, we just have this definition in our Prelude `otherwise = True`. |
| 2021-03-16 14:31:32 | <emetrusky> | yep understand that |
| 2021-03-16 14:31:55 | <emetrusky> | if everything fails then it will go to otherwise as that will be true |
| 2021-03-16 14:32:16 | → | geekosaur joins (82650c7a@130.101.12.122) |
| 2021-03-16 14:32:26 | <dminuoso> | Sure. I was just emphasizing that `otherwise` is, unlike say in math, not a specially defined keyword. |
| 2021-03-16 14:32:29 | <dminuoso> | You could have also written this as: |
| 2021-03-16 14:32:42 | <dminuoso> | f x | x > 10 = x |
| 2021-03-16 14:32:44 | <dminuoso> | | True = 2 * x |
| 2021-03-16 14:33:01 | × | Mrbuck quits (~Mrbuck@gateway/tor-sasl/mrbuck) (Quit: WeeChat 2.8) |
| 2021-03-16 14:35:49 | → | rj_ joins (~x@gateway/tor-sasl/rj) |
| 2021-03-16 14:36:06 | × | dbmikus quits (~dbmikus@cpe-76-167-86-219.natsow.res.rr.com) (Ping timeout: 260 seconds) |
| 2021-03-16 14:36:07 | <teddyc> | reading through the prelude actually removed a lot of the magic for me. Just seeing how functions like map and filer where not different to what I would implement myself. |
| 2021-03-16 14:36:16 | <teddyc> | discovere otherwise=True this way |
| 2021-03-16 14:36:24 | <teddyc> | *discovered |
| 2021-03-16 14:37:26 | × | emetrusky quits (561e1a8f@cpc152439-cosh18-2-0-cust142.6-1.cable.virginm.net) (Quit: Connection closed) |
| 2021-03-16 14:37:26 | <dminuoso> | teddyc: Would you also be surprised to learn that `data Bool = True | False`? :) |
| 2021-03-16 14:38:10 | → | epstein joins (dwsjeid911@gateway/vpn/mullvad/dwsjeid911) |
| 2021-03-16 14:38:12 | × | epstein quits (dwsjeid911@gateway/vpn/mullvad/dwsjeid911) (K-Lined) |
| 2021-03-16 14:38:24 | <teddyc> | i was sort of surprised when I read that, but I dont know why. I always think that things "included" in a language is super complex, when in many cases its not |
| 2021-03-16 14:39:18 | × | roconnor quits (~roconnor@host-45-58-230-226.dyn.295.ca) (Ping timeout: 256 seconds) |
| 2021-03-16 14:39:23 | <tomsmeding> | ADG1089__: I don't have LLVM 9 so I removed -fllvm from the flags, but both the 'cabal install' command and the 'cabal run --enable-profiling' command run ghc using -O2 for me |
| 2021-03-16 14:39:39 | <tomsmeding> | though indeed 'cabal install' compiles all executables |
| 2021-03-16 14:39:59 | → | cr3 joins (~cr3@192-222-143-195.qc.cable.ebox.net) |
| 2021-03-16 14:40:56 | × | idhugo__ quits (~idhugo@130.225.16.16) (Read error: Connection reset by peer) |
| 2021-03-16 14:41:18 | <dminuoso> | teddyc: To be fair, things like Text have some really complicated internals. But, interestingly, even Text is implement in pure Haskell. |
| 2021-03-16 14:41:34 | <dminuoso> | Well. pure GHC haskell, since text makes liberal use of highly dangerous internal GHC primitives |
| 2021-03-16 14:41:43 | <merijn> | dminuoso: Depends how you define "pure" Haskell ;) |
| 2021-03-16 14:41:53 | <dminuoso> | I just corrected myself :) |
| 2021-03-16 14:42:21 | <merijn> | teddyc: Well, there's a bunch of rewrite rules for stuff in Prelude for things like list fusion |
| 2021-03-16 14:42:39 | <merijn> | teddyc: But that doesn't (well, shouldn't!) affect the behaviour, only performance :p |
| 2021-03-16 14:42:45 | → | idhugo__ joins (~idhugo@80-62-116-180-mobile.dk.customer.tdc.net) |
| 2021-03-16 14:42:57 | × | royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed) |
| 2021-03-16 14:43:19 | → | royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) |
| 2021-03-16 14:43:25 | <geekosaur> | the Report Prelude is probably better for reading to see how Haskell works |
| 2021-03-16 14:43:37 | <teddyc> | yeah, most of it is greek to me |
| 2021-03-16 14:43:45 | <geekosaur> | ghc's Prelude shows how to make it fast :) |
| 2021-03-16 14:44:02 | <geekosaur> | (and overly general, cf. Foldable) |
| 2021-03-16 14:44:20 | <tomsmeding> | teddyc: haskell allows unicode in variable names, so you can actually make it greek :) |
| 2021-03-16 14:44:35 | <teddyc> | hoho, nice |
| 2021-03-16 14:44:43 | <dminuoso> | teddyc: Now imagine, what if even numbers were defined in plain Haskell |
| 2021-03-16 14:44:43 | × | Stanley00 quits (~stanley00@unaffiliated/stanley00) (Read error: Connection reset by peer) |
| 2021-03-16 14:44:50 | <dminuoso> | Like `data Nat = Nil | Succ Nat` |
| 2021-03-16 14:45:10 | → | Stanley00 joins (~stanley00@unaffiliated/stanley00) |
| 2021-03-16 14:45:22 | <tomsmeding> | (raising the bar quite a bit on the difference between semantics and performance) |
| 2021-03-16 14:45:44 | <dminuoso> | And it turns out, in Idris its done exactly like that (with some tricks to regain performance) |
| 2021-03-16 14:45:52 | <teddyc> | hmm interesting |
| 2021-03-16 14:45:55 | <dminuoso> | data Nat : Type where Z : Nat; S : Nat -> Nat |
| 2021-03-16 14:46:28 | <curiousgay> | merijn: actually how Go manages threads is very complicated, it tries to optimize thread usage per CPU cores and at the same time it increments the amount of OS threads dynamically where you can have thousands of OS threads on 4 core CPU (default limit is 10000), don't ask me what are the conditions to increment the amount of OS threads |
| 2021-03-16 14:47:03 | <dminuoso> | Or you could have made lists yourself too. The *only* reason its not a real Haskell definition, is because they use characters not admissable for constructors. |
| 2021-03-16 14:47:25 | <dminuoso> | Somewhere in `base` you find `data [] a = a : [a] | []` I think |
| 2021-03-16 14:48:13 | <dminuoso> | But `data List a = Nil | Cons a (List a)` is equivalent. In fact, you can even unsafeCoerce between `List a` and `[a]` and it will work mostly. :P |
| 2021-03-16 14:48:17 | <dminuoso> | So not even lists are magic |
| 2021-03-16 14:48:18 | <tomsmeding> | (in that vein: https://hackage.haskell.org/package/ghc-prim-0.4.0.0/docs/src/GHC-Tuple.html ) |
| 2021-03-16 14:48:46 | → | idhugo_ joins (~idhugo@87-49-147-45-mobile.dk.customer.tdc.net) |
| 2021-03-16 14:48:48 | × | sepples_ quits (~sepples@67.205.168.224) (Ping timeout: 245 seconds) |
| 2021-03-16 14:49:12 | → | thc202 joins (~thc202@unaffiliated/thc202) |
All times are in UTC.