Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 371 372 373 374 375 376 377 378 379 380 381 .. 5022
502,152 events total
2020-10-02 15:44:42 <Guest18> safeDiv :: (Num a, Fractional a, Eq a) => a -> a -> Either String a
2020-10-02 15:44:43 <Guest18> safeDiv _ 0 = Left "The divider is zero, computation failed"
2020-10-02 15:44:43 <Guest18> safeDiv x y = Right $ x/y
2020-10-02 15:44:56 <Guest18> Ah, forgot to get rid of $
2020-10-02 15:44:59 × machinedgod quits (~machinedg@d67-193-126-196.home3.cgocable.net) (Ping timeout: 240 seconds)
2020-10-02 15:45:03 <Guest18> Anyway, you mean like this?
2020-10-02 15:45:08 <ski> Guest18 : "Is this the way to do it?" -- anyway, it also depends on how you intend to use it, e.g. what other possibly-failing operation could you want to use, together with this ? or in what ways (if any) would you want to handle/catch the failure ?
2020-10-02 15:45:13 <ski> yes
2020-10-02 15:45:48 <ski> although `Num a' is redundant, since `Num' is a superclass of `Fractional'
2020-10-02 15:46:22 hnOsmium0001 joins (uid453710@gateway/web/irccloud.com/x-wrddzpzdlgkkaqhg)
2020-10-02 15:46:32 <Guest18> Well, I know this is a bad example, because it can only fail in one way. But say for some reason, I hate dividing by 3, so i add a pattern for that and return another string or something to signify that
2020-10-02 15:46:48 <Guest18> So i can see what actually happened
2020-10-02 15:46:59 <Guest18> Is this how Either is supposed to be used?
2020-10-02 15:47:32 <ski> (i've occasionally used e.g. `Either Integer' as a monad, or idiom. aborting some operation involving "attempts", reporting the first `Integer' that failed an attempt)
2020-10-02 15:48:22 <ski> Guest18 : it's really hard to say, without seeing the context in which you intend to use this
2020-10-02 15:49:34 thir joins (~thir@p200300f27f0fc60004d129737887aa72.dip0.t-ipconnect.de)
2020-10-02 15:49:37 <cpressey> Guest18: Yes, Either can be used this way.
2020-10-02 15:49:49 <ski> if you just want to represent possible failure, and don't care about a situation where you may want to distinguish between the possible failures of multiple operations, i'd just use `Maybe'
2020-10-02 15:50:01 × Gurkenglas quits (~Gurkengla@unaffiliated/gurkenglas) (Ping timeout: 264 seconds)
2020-10-02 15:50:12 × jedws quits (~jedws@121.209.139.222) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-10-02 15:50:15 × snakemasterflex quits (~snakemast@213.100.206.23) (Ping timeout: 258 seconds)
2020-10-02 15:50:27 <ski> if you do want to be able to distinguish between failures from different operations, then it could make more sense to use `Either'
2020-10-02 15:50:41 <Guest18> Ok, then, once i get the result, how do i extract the value? Through pattern-matching?
2020-10-02 15:51:48 LKoen joins (~LKoen@lstlambert-657-1-123-43.w92-154.abo.wanadoo.fr)
2020-10-02 15:51:57 <Uniaika> Guest18: you may, but helper functions such as `either` exist as well, to inline the case analysis
2020-10-02 15:52:03 <ski> Guest18 : again, "it depends"
2020-10-02 15:53:10 mahene joins (~mahene@2a02:8109:86c0:8d68:5400:2bfd:d746:732c)
2020-10-02 15:53:44 <ski> if this is a "one off" case, sure, you can do that. or things like `maybe',`fromMaybe',`either'. or sometimes things like `catMaybe',`mapMaybe',`partitionEithers' could be what you're looking for
2020-10-02 15:53:54 wroathe joins (~wroathe@c-73-24-27-54.hsd1.mn.comcast.net)
2020-10-02 15:53:55 × thir quits (~thir@p200300f27f0fc60004d129737887aa72.dip0.t-ipconnect.de) (Ping timeout: 240 seconds)
2020-10-02 15:54:08 × kritzefitz quits (~kritzefit@fw-front.credativ.com) (Remote host closed the connection)
2020-10-02 15:54:31 <ski> but often you e.g. want to "short-circuit" a combination of multiple possibly failing operations, so that if one operation fails, the "next one" won't be tried, instead failing the whole combination
2020-10-02 15:54:51 <ski> Guest18 : this is one thing that `Monad' (and `Applicative') is useful for
2020-10-02 15:54:52 × rotaerk quits (rotaerk@2600:3c02::f03c:91ff:fe70:4a45) (Read error: Connection reset by peer)
2020-10-02 15:56:26 rotaerk joins (~rotaerk@ender.afternet.org)
2020-10-02 15:57:55 × avdb quits (~avdb@ip-213-49-123-208.dsl.scarlet.be) (Ping timeout: 240 seconds)
2020-10-02 15:58:23 × heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2020-10-02 15:58:29 × da39a3ee5e6b4b0d quits (~textual@n11211935170.netvigator.com) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-10-02 15:59:46 Lord_of_Life joins (~Lord@unaffiliated/lord-of-life/x-0885362)
2020-10-02 15:59:51 <ski> @let safeDiv :: (Integral a,Eq a) => a -> a -> Maybe a; safeDiv _ 0 = Nothing; safeDiv n d = Just (div n d)
2020-10-02 15:59:53 <lambdabot> Defined.
2020-10-02 15:59:58 avdb joins (~avdb@37.120.137.153)
2020-10-02 16:00:02 <monochrom> It always comes down to pattern matching. The only question is do you handwrite every time or do you refactor and reuse.
2020-10-02 16:00:04 <ski> > maybe "Oops !" show (for [1,2,3,4,5,6] (\d -> safeDiv 12 d))
2020-10-02 16:00:08 <lambdabot> "[12,6,4,3,2,2]"
2020-10-02 16:00:11 <ski> > maybe "Oops !" show (for [1,2,3,0,5,6] (\d -> safeDiv 12 d))
2020-10-02 16:00:14 <lambdabot> "Oops !"
2020-10-02 16:00:29 kritzefitz joins (~kritzefit@212.86.56.80)
2020-10-02 16:00:29 Rudd0 joins (~Rudd0@185.189.115.108)
2020-10-02 16:01:00 <ski> Guest18 : that's an example of performing a sequence of possibly-failing operations, short-circuiting so that it fails (doesn't continue) as soon as an individual operation fails
2020-10-02 16:01:03 × kritzefitz quits (~kritzefit@212.86.56.80) (Client Quit)
2020-10-02 16:01:36 × kbse[m] quits (kbsematrix@gateway/shell/matrix.org/x-aveamwrjewluqtec) (Quit: Idle for 30+ days)
2020-10-02 16:02:25 nineonine joins (~nineonine@216-19-190-182.dyn.novuscom.net)
2020-10-02 16:02:27 × jgt quits (~jgt@195.225.146.77) (Ping timeout: 260 seconds)
2020-10-02 16:02:30 × cpressey quits (~cpressey@88.144.95.167) (Quit: WeeChat 1.9.1)
2020-10-02 16:06:17 × xff0x quits (~fox@2001:1a81:5254:9a00:244e:e6:b68b:8071) (Ping timeout: 272 seconds)
2020-10-02 16:06:25 xff0x joins (~fox@2001:1a81:5254:9a00:e9b2:76ba:9f0:a22b)
2020-10-02 16:06:41 howdoi joins (uid224@gateway/web/irccloud.com/x-modyeizvecmfjtqb)
2020-10-02 16:06:52 <Guest18> ski: I see, thank you for the thorough explanation. You too, Uniaika
2020-10-02 16:08:45 × hive-mind quits (~hivemind@rrcs-67-53-148-69.west.biz.rr.com) (Ping timeout: 240 seconds)
2020-10-02 16:08:49 niko is now known as ping
2020-10-02 16:09:17 hive-mind joins (~hivemind@rrcs-67-53-148-69.west.biz.rr.com)
2020-10-02 16:09:47 × bloodstalker quits (~bloodstal@46.166.187.178) (Ping timeout: 240 seconds)
2020-10-02 16:10:06 geekosaur joins (42d52102@66.213.33.2)
2020-10-02 16:11:07 <ski> > (either id absurd . (`evalStateT` 1) . forever) (do n <- get; when (n >= 1000) (throwError n); put (2 * n)) -- Guest18, another example, doubling (starting from `1'), aborting when we reach at least a thousand
2020-10-02 16:11:11 <lambdabot> 1024
2020-10-02 16:12:05 bloodstalker joins (~bloodstal@46.166.187.154)
2020-10-02 16:12:39 <ski> (if we didn't abort with `throwError' (which corresponds to `Nothing' or `Left' above, expressing (short-circuiting) failure), this would go on `forever')
2020-10-02 16:15:10 <ski> sometimes, one might also have an alternative branch (or a bunch of them), to try, in case the "main computation branch" failed. then one could reach for library operations having to do with `MonadPlus' (or `Alternative')
2020-10-02 16:16:19 thir joins (~thir@p200300f27f0fc60004d129737887aa72.dip0.t-ipconnect.de)
2020-10-02 16:16:46 <Guest18> Thank you, I'm gonna go over your examples later, i need to go now
2020-10-02 16:16:52 × Guest18 quits (567e8866@gateway/web/cgi-irc/kiwiirc.com/ip.86.126.136.102) (Quit: Connection closed)
2020-10-02 16:17:05 × jespada quits (~jespada@90.254.246.48) (Ping timeout: 258 seconds)
2020-10-02 16:18:01 jespada joins (~jespada@90.254.246.48)
2020-10-02 16:18:46 machinedgod joins (~machinedg@45.78.189.122)
2020-10-02 16:19:14 × avdb quits (~avdb@37.120.137.153) (Quit: WeeChat 2.9)
2020-10-02 16:19:32 heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net)
2020-10-02 16:20:13 <fresheyeball> anyone know how to get haddock themes to work?
2020-10-02 16:24:58 hackage blank-canvas 0.7.3 - HTML5 Canvas Graphics Library https://hackage.haskell.org/package/blank-canvas-0.7.3 (ryanglscott)
2020-10-02 16:27:49 × mahene quits (~mahene@2a02:8109:86c0:8d68:5400:2bfd:d746:732c) (Ping timeout: 272 seconds)
2020-10-02 16:29:44 chappi joins (~swaroop@157.49.95.64)
2020-10-02 16:31:21 b_52 joins (~btk@89-64-93-156.dynamic.chello.pl)
2020-10-02 16:32:49 pjb joins (~t@2a01cb04063ec50074da2bfcb3222c7a.ipv6.abo.wanadoo.fr)
2020-10-02 16:34:39 cole-h joins (~cole-h@c-73-48-197-220.hsd1.ca.comcast.net)
2020-10-02 16:35:23 tzh joins (~tzh@2601:448:c500:5300::143b)
2020-10-02 16:38:21 × conal quits (~conal@107.181.166.148) (Quit: Computer has gone to sleep.)
2020-10-02 16:38:33 × b_52 quits (~btk@89-64-93-156.dynamic.chello.pl) (Quit: Leaving)
2020-10-02 16:40:06 × voyons_osti quits (~dan@107-190-41-58.cpe.teksavvy.com) (Read error: Connection reset by peer)
2020-10-02 16:40:42 voyons_osti joins (~dan@107-190-41-58.cpe.teksavvy.com)
2020-10-02 16:40:57 zacts joins (~zacts@dragora/developer/zacts)
2020-10-02 16:41:09 × aldum quits (~vishera@aldum.pw) (Remote host closed the connection)
2020-10-02 16:41:19 aldum joins (~vishera@aldum.pw)
2020-10-02 16:41:45 slack1256 joins (~slack1256@181.203.37.183)
2020-10-02 16:42:04 × nineonine quits (~nineonine@216-19-190-182.dyn.novuscom.net) (Remote host closed the connection)
2020-10-02 16:42:06 × jespada quits (~jespada@90.254.246.48) (Quit: Leaving)
2020-10-02 16:46:43 conal joins (~conal@107.181.166.148)
2020-10-02 16:48:28 jgt joins (~jgt@188.239.64.32)
2020-10-02 16:49:43 × conal quits (~conal@107.181.166.148) (Client Quit)
2020-10-02 16:50:06 × finkata quits (~dpetrov@83.222.188.39) (Remote host closed the connection)
2020-10-02 16:50:24 conal joins (~conal@107.181.166.148)

All times are in UTC.