Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 540 541 542 543 544 545 546 547 548 549 550 .. 5022
502,152 events total
2020-10-09 18:38:50 <Cale> yeah
2020-10-09 18:38:52 <Guest18> Yeah, actually that makes sense
2020-10-09 18:38:57 <ski> tomsmeding : hm, i didn't really had in mind that it would be. i just wondered how to express it, with `reads'
2020-10-09 18:39:04 <Guest18> i don't know why i didnt see that
2020-10-09 18:39:14 <ski> tomsmeding : hm, i don't recall it used to break line, quite that early
2020-10-09 18:39:25 <monochrom> depth should be "depth x tree = depthGo x tree 0" very simply, no more no less.
2020-10-09 18:39:33 <tomsmeding> ski: ah I see
2020-10-09 18:39:43 <Guest18> I am programming in haskell for one week so my code can be sketchy sometimes
2020-10-09 18:39:44 <monochrom> For example there is no point "depth" cares about empty trees.
2020-10-09 18:40:02 <Cale> also, you can do: depthGo x (Node root left right) acc = case compare x root of EQ -> ...; LT -> ...; GT -> ...
2020-10-09 18:40:05 <Guest18> i see, yeah
2020-10-09 18:40:15 <monochrom> Well in this case I'm just using the DRY principle.
2020-10-09 18:40:18 <Cale> Which will only compute the comparison once, and match on the result
2020-10-09 18:40:30 × _deepfire quits (~user@80.92.100.69) (Remote host closed the connection)
2020-10-09 18:40:53 × alp_ quits (~alp@2a01:e0a:58b:4920:a813:2213:43c8:3e1b) (Remote host closed the connection)
2020-10-09 18:41:18 alp_ joins (~alp@2a01:e0a:58b:4920:b989:9831:f361:9cf)
2020-10-09 18:41:25 × ryansmccoy quits (~ryansmcco@156.96.151.132) (Ping timeout: 240 seconds)
2020-10-09 18:42:09 ryansmccoy joins (~ryansmcco@193.37.254.27)
2020-10-09 18:42:43 <ski> Guest18 : instead of using an accumulator, it would be possible to do the addition "after the recursive call"
2020-10-09 18:43:12 × thc202 quits (~thc202@unaffiliated/thc202) (Ping timeout: 260 seconds)
2020-10-09 18:43:14 <Guest18> ski: isn't the accumulator letting the compiler use tail call optimization?
2020-10-09 18:43:25 <monochrom> That turns out to be much uglier in this case. And don't even get me started on efficiency.
2020-10-09 18:43:53 <ski> Guest18 : yes, that might be preferrable (at least if you'd be using say `Int' or `Integer' ..) .. but then you should make sure to force the accumulator, as you go
2020-10-09 18:44:13 <monochrom> Because you then have to say "if the recursion gives you Nothing, nothing to add" and "if the recursion gives you Just n, now it's Just (n+1)"
2020-10-09 18:44:23 <ski> Guest18 : but ignoring such performance considerations, a non-accumulating version can often be more readable
2020-10-09 18:44:31 <ski> yea, there's that
2020-10-09 18:45:17 <ski> Guest18 : depending, it's commonly preferable to not be tail-recursive
2020-10-09 18:45:23 <monochrom> For computing tree height or tree size, yes I would do "1 + height left + height right".
2020-10-09 18:45:52 <monochrom> In fact for height and size, tail recursion is the much uglier one.
2020-10-09 18:45:58 <ski> (but in this case, you're just computing a single number, so there's not much point to that, here)
2020-10-09 18:46:05 <monochrom> Also throughout, my "ugly" includes both ugly and hard to follow.
2020-10-09 18:46:10 <dolio> monochrom: Not only that, it's easier to not be better than an accumulator with that. :)
2020-10-09 18:46:18 <monochrom> because they are caused by complications
2020-10-09 18:46:18 <dolio> An unforced accumulator, that is.
2020-10-09 18:47:00 <ski> (i suppose an alternative here would be CPS ..)
2020-10-09 18:47:23 <monochrom> Oh CPS is the most unreadable of them all haha
2020-10-09 18:47:52 <ski> hm, i think it could be more readable than doing `case's
2020-10-09 18:48:14 <Guest18> https://dpaste.com/DRF3G9AA6 -- any other suggestions?
2020-10-09 18:48:17 <ski> (as long as one's familiar with CPS, of course)
2020-10-09 18:48:46 <ski> Guest18 : your `Show' instance is incorrect
2020-10-09 18:49:22 <monochrom> <CPS> Mirror mirror, who's the most unreadable of them all? <Mirror> You, in all Haskell Land. <CPS> But I mean universally, not just Haskell Land. <Mirror> Then it's your step daughter, CPS+trampolining, she's is Javascript Forest now.
2020-10-09 18:49:23 geekosaur joins (82659a05@host154-005.vpn.uakron.edu)
2020-10-09 18:49:44 <Guest18> ski: how so? it works fine for me
2020-10-09 18:50:02 <ski> Guest18 : it doesn't output valid Haskell source
2020-10-09 18:50:17 <dolio> monochrom: That's why you need delimited continuations, to make it perfectly clear.
2020-10-09 18:50:47 × thir quits (~thir@p200300f27f02580060eb7dde324e54c8.dip0.t-ipconnect.de) (Ping timeout: 260 seconds)
2020-10-09 18:50:59 <monochrom> <CPS> I'm going to give reactive node.js thingy to Javascript Forest to poison them all!
2020-10-09 18:51:06 Ariakenom__ joins (~Ariakenom@h-155-4-221-50.NA.cust.bahnhof.se)
2020-10-09 18:51:11 nyd joins (~lpy@unaffiliated/elysian)
2020-10-09 18:51:21 <Guest18> ski: why should it? I just wanted a more readable version, so i can debug easily
2020-10-09 18:51:23 <ski> Guest18 : if you want to do custom pretty-printing, then please don't use `Show' for that. (`Show' instances are meant to work together. your instance, when combined with other `Show' instances, will produce a mixture of Haskell and non-Haskell code). please define a separate function, say `displayTree'
2020-10-09 18:51:39 <Guest18> ski: oh, okay
2020-10-09 18:51:52 <Guest18> That actually makes sense
2020-10-09 18:52:19 <geekosaur> also Show and Read are designed to work together such that the output of a valid Show instance can be passed to `read'
2020-10-09 18:52:51 <ski> Haskell will automatically combine instances like this, e.g. if you were to display a list of type `[BST (BST a)]'
2020-10-09 18:52:58 <ski> yes, that too
2020-10-09 18:53:00 <tomsmeding> monochrom: :D
2020-10-09 18:53:08 <Guest18> I also have a flatten, insert, search and fromList functions and want to add some more. I'm really digging how easy it is to make these kind of stuff in Haskell
2020-10-09 18:54:25 × Ariakenom_ quits (~Ariakenom@h-155-4-221-50.NA.cust.bahnhof.se) (Ping timeout: 240 seconds)
2020-10-09 18:55:20 Pasalmachow joins (~textual@2601:643:8000:a570:9513:b921:a468:618c)
2020-10-09 18:55:23 × vicfred quits (~vicfred@unaffiliated/vicfred) (Quit: Leaving)
2020-10-09 18:56:03 × Pasalmachow quits (~textual@2601:643:8000:a570:9513:b921:a468:618c) (Client Quit)
2020-10-09 18:56:18 <ski> Guest18 : there are cases when one may want to make a hand-written `Show' (and `Read') instance. e.g. when the implementation can't manage to derive one for you. or when you're making an abstract data type, and don't want to expose your implementation, but rather display a value in terms of the exported operations
2020-10-09 18:57:24 × heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2020-10-09 18:59:43 <Guest18> yeah, this was more for the educational value than naything else
2020-10-09 19:00:06 Sososasa joins (~textual@2601:643:8000:a570:9513:b921:a468:618c)
2020-10-09 19:00:35 <Guest18> follow up question
2020-10-09 19:01:21 <dwts> Which haskell book would you guys suggest for someone new to haskell but not new to programming? I've started "Get programming with Haskell" but I'm not very happy with it
2020-10-09 19:02:17 <Guest18> say i have the following line of code: `[depth x tree | x <- flatten tree]`. How do i sum up these depths? Since they are wrapped in a Just, I can't just use `sum` on the list
2020-10-09 19:02:20 × gxt quits (~gxt@gateway/tor-sasl/gxt) (Remote host closed the connection)
2020-10-09 19:02:51 <Cale> dwts: Graham Hutton's Programming in Haskell seems pretty good
2020-10-09 19:03:01 <dwts> To help you understand what I don't like: 1) it doesn't explain how to indent code 2) it doesn't explain how to read function definitions
2020-10-09 19:03:09 <dwts> Cale: thank you sir
2020-10-09 19:03:12 GyroW_ joins (~GyroW@d54c03e98.access.telenet.be)
2020-10-09 19:03:12 × GyroW_ quits (~GyroW@d54c03e98.access.telenet.be) (Changing host)
2020-10-09 19:03:12 GyroW_ joins (~GyroW@unaffiliated/gyrow)
2020-10-09 19:03:15 gxt joins (~gxt@gateway/tor-sasl/gxt)
2020-10-09 19:03:17 <Cale> Guest18: What do you want to do if there's a Nothing?
2020-10-09 19:03:36 berberman_ joins (~berberman@unaffiliated/berberman)
2020-10-09 19:03:40 <Cale> Guest18: Oh, of course there won't be
2020-10-09 19:03:47 × berberman quits (~berberman@unaffiliated/berberman) (Ping timeout: 240 seconds)
2020-10-09 19:04:26 × GyroW quits (~GyroW@unaffiliated/gyrow) (Ping timeout: 256 seconds)
2020-10-09 19:04:55 <Cale> Guest18: One cute way is to write [d | x <- flatten tree, Just d <- [depth x tree]]
2020-10-09 19:05:30 <Cale> But it seems a bit expensive to be doing it like this
2020-10-09 19:05:35 <Guest18> Cale: yeah, there will never be nothing
2020-10-09 19:06:17 vicfred joins (~vicfred@unaffiliated/vicfred)
2020-10-09 19:06:29 <monochrom> <pun>Just cause to use fromJust? >:) </pun>
2020-10-09 19:06:34 <Cale> You're going to end up paying the price to look up every element of the tree, when ideally you'd do none of that work
2020-10-09 19:07:47 <monochrom> More realistically, how about directly write a function that computes the list of all depths of all internal nodes?
2020-10-09 19:08:13 <monochrom> Or even, a tree of the same shape but keys are replaced by depths; then use flatten.
2020-10-09 19:08:22 <Cale> yeah
2020-10-09 19:08:24 cr0ssw1nd joins (~crosswind@adsl-174.176.58.193.tellas.gr)
2020-10-09 19:08:51 <Cale> avoid all the order comparisons
2020-10-09 19:08:58 <Guest18> monochrom: i like the first idea, seems pretty efficient
2020-10-09 19:08:58 <ski> monochrom : Just because
2020-10-09 19:09:54 <Guest18> so using fromJust is expensive?
2020-10-09 19:10:18 <koz_> Guest18: It's not expensive, it's just error-prone, and you wanna avoid it if possible.
2020-10-09 19:10:19 <ski> no, repeatedly traverersing down the tree, for every element in it, is
2020-10-09 19:10:20 <geekosaur> no, Just a bad idea
2020-10-09 19:10:22 <monochrom> No. It's just unsatisfactory.

All times are in UTC.