Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-04-01 21:52:50 <nut> so I'm tying out all alternatives
2021-04-01 21:52:56 <koz_> Then I will say one thing: most algorithms are presented in a way that's awkward to translate to immutability and functional programming in general.
2021-04-01 21:53:07 <koz_> Therefore, I'd say that it's probably _not_ the most convenient of things.
2021-04-01 21:53:21 <koz_> In-place quicksort is a perfect example.
2021-04-01 21:53:33 <nut> but i do want to know the cononical way of doing these things in haskell_1 l
2021-04-01 21:53:47 <L29Ah> nut: in haskell you may opt to use a pure functional sort of an algorithm, that might be slower but have useful properties, like cheap copies that reuse most of the structure, or some laziness
2021-04-01 21:54:02 <koz_> L29Ah: For in-place quicksort, none of the above applies.
2021-04-01 21:54:09 <koz_> And there isn't a 'canonical' array sort in Haskell.
2021-04-01 21:54:14 nbloomf joins (~nbloomf@2600:1700:ad14:3020:d987:a6e5:6815:ac7d)
2021-04-01 21:54:20 <koz_> We have a bunch in vector-algorithms, they all have tradeoffs.
2021-04-01 21:54:42 <koz_> (and they all use mutability admittedly, since they're all in-place)
2021-04-01 21:55:26 <nut> Ok in a summary, whenever i have to use in place mutability algorithm, i will try ST monad
2021-04-01 21:55:34 <koz_> Yeah, that's a good summary.
2021-04-01 21:55:43 <nut> Thanks a lot!
2021-04-01 21:55:47 <koz_> (with the caveat that it's not as necessary as you might think)
2021-04-01 21:55:58 <koz_> I can give an example from my own experience where using ST made my program _slower_.
2021-04-01 21:56:04 <koz_> (and like, a _tonne_ slower)
2021-04-01 21:56:10 <nut> do tell
2021-04-01 21:56:12 <koz_> (we're talking an order of magnitude or two)
2021-04-01 21:56:19 <koz_> Block reversal.
2021-04-01 21:56:33 <koz_> The implementation I was working from used stacked looping and a mutable position variable.
2021-04-01 21:56:38 <koz_> That ran like utter garbage.
2021-04-01 21:56:47 <koz_> I then rethought it without mutable references.
2021-04-01 21:56:53 <koz_> It ran about 100 times faster.
2021-04-01 21:57:02 <moet> nut: if you're having trouble with ST, don't let it distract you from your goal.. i'd implement your goal with the pure functions (and/or ones that don't use ST) in Data.Vector first and then go back to use ST later if you want to optimize.
2021-04-01 21:57:06 <koz_> To give more specifics requires a trainload of context.
2021-04-01 21:57:10 <moet> nut: premature optimization is a killer :)
2021-04-01 21:57:15 <koz_> Most of which is not very interesting or informative.
2021-04-01 21:57:38 <nut> i understnad koz_
2021-04-01 21:58:39 <nut> moet: so if i use immutable vector instead of ST mutable vectors, that would mean a lot of vector copying, same as if i use List right?
2021-04-01 21:58:44 × hexfive quits (~hexfive@50.35.83.177) (Quit: i must go. my people need me.)
2021-04-01 21:58:47 <koz_> nut: Not necessarily.
2021-04-01 21:59:01 <koz_> Vector uses a lot of fusion tricks to avoid allocating intermediates where possible.
2021-04-01 21:59:14 <koz_> Also, depending on what you're trying to do, you can reformulate your program not to need those.
2021-04-01 21:59:27 <koz_> (heck, just 'generate' from vector is surprisingly powerful)
2021-04-01 21:59:33 <nut> but that's internal stuff right? the fusion tricks. The code still looks at if they are copying
2021-04-01 21:59:43 <koz_> nut: How is that relevant?
2021-04-01 21:59:55 <koz_> What does and doesn't get done in a pure function in Haskell is pretty theoretical anyway.
2021-04-01 22:00:05 <nut> it's not, just trying to understand the whole thing
2021-04-01 22:00:42 <koz_> The whole thing amounts to 'there are cases where intermediate stuff disappears or never gets allocated to begin with - if this is fast enough, you can safely ignore it and enjoy the benefits of immutability'.
2021-04-01 22:00:51 <koz_> (and composition etc)
2021-04-01 22:01:00 × nbloomf quits (~nbloomf@2600:1700:ad14:3020:d987:a6e5:6815:ac7d) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2021-04-01 22:01:05 <nut> As another summary, can i understand that if i use vector instead of list, most of the algorithms in the book will be faster?
2021-04-01 22:01:12 <koz_> It depends.
2021-04-01 22:01:22 <L29Ah> how do i ask hspec to run my executable?
2021-04-01 22:01:27 × coot quits (~coot@37.30.55.131.nat.umts.dynamic.t-mobile.pl) (Quit: coot)
2021-04-01 22:01:38 <koz_> L29Ah: As in, you have an hspec-based test suite and you wanna run it?
2021-04-01 22:01:44 <monochrom> Which book is "the" book?
2021-04-01 22:01:49 <koz_> Or you need to call an external executable _from_ an hspec test
2021-04-01 22:01:51 <koz_> ?
2021-04-01 22:01:55 <monochrom> Especially since Easter is so close.
2021-04-01 22:02:04 <nut> monochrom: CLRS, introduction to algorithms
2021-04-01 22:02:09 Guest_71 joins (2dab71b6@45.171.113.182)
2021-04-01 22:02:17 <moet> nut: it might be lots of copying, but fixing that before you've implement your algorithm is premature optimization .. it'll be more productive to have a working implementation first probably, and then go learn ST monad after you're comfortable with the pure implementation
2021-04-01 22:02:31 <L29Ah> koz_: no, i have a hspec-based test suite, and i want to add another test in it that runs the executable under test, as opposed to parts of its internal API
2021-04-01 22:02:33 <monochrom> Well that one downright assumes you even have mutable tree nodes. So nevermind arrays.
2021-04-01 22:02:51 <moet> nut: and as koz_ points out, list/vector fusion will make many operations in the pure implementation more efficient
2021-04-01 22:03:04 <koz_> Again, it depends.
2021-04-01 22:03:07 <moet> nut: so it'll do less copying than you think
2021-04-01 22:03:14 × Guest_71 quits (2dab71b6@45.171.113.182) (Client Quit)
2021-04-01 22:03:19 <nut> moet: there's list fusion?
2021-04-01 22:03:20 <koz_> And even if it does, it can sometimes be better to copy than not to!
2021-04-01 22:03:24 Guest_1 joins (50e93b6c@80.233.59.108)
2021-04-01 22:03:26 <koz_> See 'false sharing' for a good example.
2021-04-01 22:03:30 <koz_> nut: Yes.
2021-04-01 22:03:35 × heatsink quits (~heatsink@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2021-04-01 22:04:27 <moet> nut: yeah, fusion is a thing where a function that copies a structure has a "rewrite rule" to use a version that streams the operation rather than returning a copy; ref: 'Hermit in the Stream'
2021-04-01 22:04:40 <L29Ah> is there a better way than adding a pseudo-main function that gets the program arguments as an argument, and call it from the real main?
2021-04-01 22:04:43 <koz_> There's various kinds.
2021-04-01 22:04:43 nbloomf joins (~nbloomf@76.217.43.73)
2021-04-01 22:05:04 <moet> yeah, that's just the kind in the reference; sorry
2021-04-01 22:05:42 × jjhoo quits (jahakala@dsl-trebng21-b048b5-171.dhcp.inet.fi) (Remote host closed the connection)
2021-04-01 22:05:48 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-04-01 22:06:11 × dyamon quits (~dyamon@cpc69058-oxfd26-2-0-cust662.4-3.cable.virginm.net) (Ping timeout: 260 seconds)
2021-04-01 22:06:12 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-04-01 22:06:26 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 240 seconds)
2021-04-01 22:06:30 <moet> L29Ah: what is your hspec going to test about the behavior of `main :: IO ()`?
2021-04-01 22:06:50 <nut> I will start with pure code first. but just out of curiosity, how to choose between IOVector and STVector?
2021-04-01 22:06:53 × Tario quits (~Tario@201.192.165.173) (Ping timeout: 246 seconds)
2021-04-01 22:06:55 <moet> L29Ah: that would require some complicated test harness to inject environmental inputs and measure environmental outputs
2021-04-01 22:07:10 <monochrom> Just choose STVector
2021-04-01 22:07:14 <koz_> Are you in IO already: if yes, IOVector, otherwise STVector.
2021-04-01 22:07:22 <moet> L29Ah: if you can rephrase the features you want to test in terms of inputs and outputs of a function, your testing life will be easier
2021-04-01 22:07:24 <L29Ah> moet: not `main :: IO ()` but `system :: ByteString -> IO ExitCode` or such
2021-04-01 22:08:24 L29Ah is too lazy to stubize all the environment for backup-making software
2021-04-01 22:08:26 Tario joins (~Tario@200.119.184.73)
2021-04-01 22:08:40 <moet> L29Ah: yeah, that's a start.. i conventionally call that main2 and write a small main to call `getArgs >>= main2 >>= System.exit` or somesuch
2021-04-01 22:08:56 <L29Ah> ok thanks
2021-04-01 22:09:09 × molehillish quits (~molehilli@2600:8800:8d06:1800:49e2:dd02:cb68:846) (Remote host closed the connection)
2021-04-01 22:09:12 <moet> L29Ah: if it's third party software, you'd want main2 to be some CreateProcess from the process package
2021-04-01 22:09:42 × nbloomf quits (~nbloomf@76.217.43.73) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2021-04-01 22:09:42 <L29Ah> the sad thing is that i can't do things like +RTS -M100M
2021-04-01 22:09:47 × ddellaco_ quits (~ddellacos@ool-44c73afa.dyn.optonline.net) (Remote host closed the connection)
2021-04-01 22:10:02 <moet> L29Ah: sorry, i don't follow..
2021-04-01 22:10:03 <L29Ah> so that it would fail if it exceeds a memory limit
2021-04-01 22:10:21 <nut> is the ST, strick thread, has anything to do with haskell thread? I mean multi-threading?
2021-04-01 22:10:29 <L29Ah> moet: i want my test to verify that main2 doesn't exceed a set amount of RAM
2021-04-01 22:10:35 <monochrom> No.
2021-04-01 22:10:45 <L29Ah> using CreateProcess i can do things like +RTS -M100M
2021-04-01 22:10:46 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Ping timeout: 240 seconds)

All times are in UTC.