Logs: freenode/#haskell
| 2020-11-24 08:18:12 | <merijn> | dminuoso: I think I just linked that to my brother :p |
| 2020-11-24 08:19:03 | <dminuoso> | merijn: Did you also see the related issue? |
| 2020-11-24 08:19:09 | <dminuoso> | Or try and git blame that? |
| 2020-11-24 08:19:30 | <merijn> | No, because I already have enough things to be depressed about |
| 2020-11-24 08:19:46 | <dminuoso> | https://github.com/DaveGamble/cJSON/issues/255 https://github.com/DaveGamble/cJSON/commit/65541b900c740e1d527cd4f1935eec3740d4d95a |
| 2020-11-24 08:19:50 | <dminuoso> | It'll make you happy! |
| 2020-11-24 08:20:19 | <dminuoso> | It's not even just poor reasons. It's a plain "I cant say why" |
| 2020-11-24 08:21:41 | <dminuoso> | "because of inaccuracies when reserving memory" memory allocates are usually fuzzy! |
| 2020-11-24 08:21:56 | <dminuoso> | Maybe malloc should take a float :> |
| 2020-11-24 08:22:04 | → | chele joins (~chele@91.65.110.162) |
| 2020-11-24 08:22:52 | → | n0042 joins (d055ed89@208.85.237.137) |
| 2020-11-24 08:24:22 | → | caecilius joins (~caecilius@pool-108-46-151-95.nycmny.fios.verizon.net) |
| 2020-11-24 08:24:44 | <n0042> | Hello fellow Haskellians, Haskellites, Haskellers, and users of Haskell in general. I am interested in reading some articles on writing highly optimized Haskell, if anyone has any they are fond of. |
| 2020-11-24 08:26:16 | → | chkno joins (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) |
| 2020-11-24 08:26:19 | <dminuoso> | https://downloads.haskell.org/ghc/latest/docs/html/users_guide/sooner.html |
| 2020-11-24 08:26:23 | <n0042> | I am currently taking a class that is designed for people using imperative languages (in particular C++ and Java), but they offer the option of using Haskell, and I'm having trouble getting it to meet the time and space requirements. I know it's possible, or they wouldn't offer the option. I'd like to read up on tips and tricks to write Haskell in |
| 2020-11-24 08:26:23 | <n0042> | a very time/space-conscious way |
| 2020-11-24 08:26:32 | <dminuoso> | https://downloads.haskell.org/ghc/latest/docs/html/users_guide/profiling.html#profiling |
| 2020-11-24 08:26:53 | <n0042> | Thank you friend. I'll start there. |
| 2020-11-24 08:27:14 | <merijn> | dminuoso: You forgot the all important "+RTS -sstderr" |
| 2020-11-24 08:27:34 | <merijn> | n0042: Compile with -rtsopts and run with "+RTS -sstderr" to get GC diagnostics |
| 2020-11-24 08:27:57 | → | plutoniix joins (~q@ppp-124-121-237-69.revip2.asianet.co.th) |
| 2020-11-24 08:28:14 | → | Boomerang joins (~Boomerang@xd520f68c.cust.hiper.dk) |
| 2020-11-24 08:28:31 | → | ubert joins (~Thunderbi@p200300ecdf1e539ce6b318fffe838f33.dip0.t-ipconnect.de) |
| 2020-11-24 08:28:32 | × | chkno quits (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) (Read error: Connection reset by peer) |
| 2020-11-24 08:29:22 | <dminuoso> | n0042: Writing efficient Haskell is usually a mixture of ensuring inlining/specialization/fusion occurs, identifying sharing opportunities, chosing the right data structures ([] vs Vector), etc |
| 2020-11-24 08:29:39 | <dminuoso> | And controlling strictness |
| 2020-11-24 08:29:54 | → | aloiscochard[m] joins (aloiscocha@gateway/shell/matrix.org/x-lbvqcwwuqmskblks) |
| 2020-11-24 08:30:24 | <dminuoso> | But the above articles are a good starting point |
| 2020-11-24 08:30:24 | <n0042> | The way the class works means I know which flags will be used to compile the code I turn in (ghc -O), but beyond that it's all down to how I choose to write it. Those are the kinds of tips I need, for sure. |
| 2020-11-24 08:30:36 | <n0042> | I'll read those articles and look into more Data structure types. Thank you. |
| 2020-11-24 08:30:41 | → | mpereira joins (~mpereira@2a02:810d:f40:d96:f587:a442:5e3:1e55) |
| 2020-11-24 08:30:46 | <dminuoso> | The class will compile your code with `ghc -O`? |
| 2020-11-24 08:30:51 | <n0042> | yessir |
| 2020-11-24 08:31:13 | <aloiscochard[m]> | hey there, I'm wondering if there is vim/emacs users that are still using codex? of if everyone moved to the LSP stuff? |
| 2020-11-24 08:31:25 | <dminuoso> | aloiscochard[m]: Most IDE efforts have moved to LSP stuff. |
| 2020-11-24 08:31:50 | → | Yumasi joins (~guillaume@2a01cb09b06b29ea1c5ab82b3b485150.ipv6.abo.wanadoo.fr) |
| 2020-11-24 08:31:50 | <dminuoso> | n0042: should be fine then. |
| 2020-11-24 08:32:15 | → | acagastya joins (~acagastya@wikinews/acagastya) |
| 2020-11-24 08:32:39 | × | Sgeo_ quits (~Sgeo@ool-18b982ad.dyn.optonline.net) (Read error: Connection reset by peer) |
| 2020-11-24 08:32:43 | <dminuoso> | n0042: Out of curiosity, is this some high performance task, or are you just struggling with basic performance compared to off-the-mill Java/C++? |
| 2020-11-24 08:33:41 | <acagastya> | Hi, I was trying out how to write the finobacci function in haskell, <https://0x0.st/iRe7.hs> but I am getting stack overflow for `fib 2`. I don't understand why. |
| 2020-11-24 08:34:12 | <merijn> | acagastya: You're infinite looping |
| 2020-11-24 08:34:16 | <dminuoso> | acagastya: Spaces dont affect associativity |
| 2020-11-24 08:34:19 | <merijn> | acagastya: fib n calls "fib n" |
| 2020-11-24 08:34:20 | <dminuoso> | Use parens |
| 2020-11-24 08:34:36 | <merijn> | acagastya: You're not calling "fib (n-1)" |
| 2020-11-24 08:35:41 | <n0042> | dminuoso: It's a Data Structures and Algorithms class, and the goal for most of the assignments is to force you to use the right data structure in a really time/space-conscious way. I'm having a little trouble translating the solutions I'd have chosen in C into idiomatic and performant Haskell |
| 2020-11-24 08:35:54 | <acagastya> | All right. So, what I wrote was actually evaluating `-3 + 2 * fib n`, right? |
| 2020-11-24 08:35:55 | × | eyenx quits (~eyenxeyen@unaffiliated/eye/x-1653358) (Quit: Bridge terminating on SIGTERM) |
| 2020-11-24 08:35:57 | → | jonathanx joins (~jonathan@dyn-8-sc.cdg.chalmers.se) |
| 2020-11-24 08:36:12 | <dminuoso> | n0042: I see, so that can be a bit more tricky. |
| 2020-11-24 08:36:16 | <acagastya> | (Thanks, merijn, dminuoso.) |
| 2020-11-24 08:36:16 | → | chkno joins (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) |
| 2020-11-24 08:36:21 | → | eyenx joins (~eyenxeyen@unaffiliated/eye/x-1653358) |
| 2020-11-24 08:36:51 | <dminuoso> | n0042: Algorithms are usually implemented differently in a pure functional setting, so naive approaches tend to perform poorly. |
| 2020-11-24 08:36:51 | × | chkno quits (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) (Read error: Connection reset by peer) |
| 2020-11-24 08:37:08 | <dminuoso> | n0042: What kind of algorithms are these? |
| 2020-11-24 08:37:28 | <merijn> | acagastya: well, no more like "how do I compute 'fib 5'? well, first I compute 'fib 5'. How do I compute 'fib 5'? repeat" :p |
| 2020-11-24 08:38:33 | <n0042> | Well an example of one I am having trouble getting under the time requirement is a network packet simulation. All input and output has to be done during runtime (no command line arguments). It inputs the number of packets, the size of the "buffer", and the arrival time and time-to-process for each packet, and you have to calculate the time at |
| 2020-11-24 08:38:34 | <n0042> | which each packet will begin processing |
| 2020-11-24 08:38:34 | <acagastya> | I don't know why I was under the impression `fib n-1` will first compute `n-1` and then call `fib`. |
| 2020-11-24 08:39:01 | <n0042> | My solution is just a smidge too slow, even with the extra time they allot for using Haskell instead of C. It's close though. I just need to learn more about optimizing Haskell code. |
| 2020-11-24 08:39:12 | <merijn> | acagastya: Simple rule to remember is that function application *always* binds tighter than operators |
| 2020-11-24 08:39:29 | <xerox_> | acagastya: fib $ n-1 does |
| 2020-11-24 08:39:31 | <merijn> | n0042: Are you doing something naive like using a list like an array? |
| 2020-11-24 08:39:37 | <dminuoso> | n0042: Out of curiosity, can you share your code? Perhaps we could give you some rough hints and pointers. |
| 2020-11-24 08:39:57 | <dminuoso> | Want to stress that I dont intend to spoonfeed, but perhaps nudging you in the right direction is easier then |
| 2020-11-24 08:40:15 | <merijn> | dminuoso: Like seeing if there's any lists/String anywhere ;) |
| 2020-11-24 08:40:19 | <dminuoso> | ;) |
| 2020-11-24 08:40:27 | × | Boomerang quits (~Boomerang@xd520f68c.cust.hiper.dk) (Remote host closed the connection) |
| 2020-11-24 08:40:29 | × | lambda-11235 quits (~lambda-11@2600:1700:7c70:4600:34e8:32b9:5cc3:48e6) (Quit: Bye) |
| 2020-11-24 08:40:36 | <n0042> | Actually I implemented an array inside a data structure that keeps track of the read/write head, as a Queue, but I'm sure I made the rest of the function too inefficient. I used lists for processing input/output and for some intermediate steps |
| 2020-11-24 08:40:47 | → | Boomerang joins (~Boomerang@xd520f68c.cust.hiper.dk) |
| 2020-11-24 08:40:52 | <merijn> | n0042: Ah! How di you implement you array? |
| 2020-11-24 08:40:59 | <n0042> | Using lists elsewhere probably defeated the purpose of using an array. |
| 2020-11-24 08:41:05 | <dminuoso> | When you say "array" |
| 2020-11-24 08:41:07 | <dminuoso> | what do you mean exactly? |
| 2020-11-24 08:41:11 | <n0042> | I hesitate to share the code as the class is still in progress |
| 2020-11-24 08:41:16 | → | chkno joins (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) |
| 2020-11-24 08:41:33 | <n0042> | like: `listArray (0,3) (replicate 4 0)` kind of array. |
| 2020-11-24 08:41:33 | × | chkno quits (~chkno@75-7-2-127.lightspeed.sntcca.sbcglobal.net) (Read error: Connection reset by peer) |
| 2020-11-24 08:41:43 | <n0042> | which I then just treated like something I could read-write to at will |
| 2020-11-24 08:41:49 | <merijn> | ah |
| 2020-11-24 08:41:55 | <merijn> | ok, for reading that's fine |
| 2020-11-24 08:42:02 | <merijn> | for writing...it depends |
| 2020-11-24 08:42:57 | <n0042> | When you write to it with the `//` it must create a new array, right? Is that "expensive"? |
| 2020-11-24 08:43:22 | <merijn> | It has to copy the entire thing. For an array of 4 elements that's probably not so bad, but not ideal |
| 2020-11-24 08:43:34 | <n0042> | Can be up to 10^5, so that's probably my error |
| 2020-11-24 08:44:00 | <dminuoso> | n0042: Run it through the profiler |
| 2020-11-24 08:44:00 | <n0042> | It passes all the tests until the last one, which is a buffer size of 10^5 processing 10^5 "packets" |
| 2020-11-24 08:44:05 | <merijn> | n0042: oof, yes |
| 2020-11-24 08:44:25 | <dminuoso> | n0042: Because its very likely it could have told you already :) |
| 2020-11-24 08:44:38 | <merijn> | n0042: Incidentally, the vector package has proper mutable arrays inside, if you only need 1 dimensional arrays |
| 2020-11-24 08:44:55 | <n0042> | Excellent. Profiling and Vectors seem like good places to start |
| 2020-11-24 08:45:00 | <n0042> | Thank you all very much |
| 2020-11-24 08:45:43 | <merijn> | But yeah, profile :p |
| 2020-11-24 08:45:44 | <merijn> | oh |
| 2020-11-24 08:45:50 | <merijn> | dminuoso: You forgot the most important thing |
| 2020-11-24 08:46:15 | <merijn> | n0042: If you're using GHC 8.10, lemme mention out performance lord & saviour: https://mpickering.github.io/posts/2019-11-07-hs-speedscope.html |
All times are in UTC.