Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-04-18 23:47:45 <Axman6> this is known at the Applicative pattern
2021-04-18 23:48:02 × fiedlr quits (~fiedlr@83.148.33.254) (Remote host closed the connection)
2021-04-18 23:48:19 fiedlr joins (~fiedlr@83.148.33.254)
2021-04-18 23:48:21 <lechner> i read about that yesterday, but only got half of it.
2021-04-18 23:48:36 <Axman6> given a function f :: a -> b -> c -> d, and fa :: f a, fb :: f b, fc :: f c, the expression f <$> fa <*> fb <*> fc has type f d
2021-04-18 23:49:08 <Axman6> it allows us to turn a function of type a -> b ... -> z into a function of type f a -> f b -> ... -> f z
2021-04-18 23:49:29 <lechner> that part i got. i did not understand now and where to use such a powerful construct
2021-04-18 23:49:33 <lechner> how
2021-04-18 23:49:48 <Axman6> so, imagine f is Maybe, you can add the values in teo Maybe Int's by using (+) <$> Just 3 <*> Just 5
2021-04-18 23:49:58 <lechner> it's a generalization of map
2021-04-18 23:50:02 <Axman6> everywhere :)
2021-04-18 23:50:10 <koz_> It's a generalization of function application.
2021-04-18 23:50:14 <Axman6> > (+) <$> Just 4 <*> Just 5
2021-04-18 23:50:15 <lechner> right
2021-04-18 23:50:16 <koz_> Here's the key idea.
2021-04-18 23:50:16 <lambdabot> Just 9
2021-04-18 23:50:18 <koz_> :t ($)
2021-04-18 23:50:20 <lambdabot> (a -> b) -> a -> b
2021-04-18 23:50:22 <Axman6> > (+) <$> Just 4 <*> Nothing
2021-04-18 23:50:24 <koz_> :t (<*>)
2021-04-18 23:50:24 <lambdabot> Nothing
2021-04-18 23:50:25 <lambdabot> Applicative f => f (a -> b) -> f a -> f b
2021-04-18 23:50:35 <koz_> Notice how the only difference is that 'f' there?
2021-04-18 23:50:43 <koz_> That 'f' is 'an effect'.
2021-04-18 23:50:51 <lechner> it adds the monad
2021-04-18 23:50:57 <koz_> So while ($) is 'pure function application', (<*>) is 'effectful function application'.
2021-04-18 23:51:15 × hiroaki_ quits (~hiroaki@2a02:908:4b18:8c40:2bbc:3100:411b:408e) (Ping timeout: 260 seconds)
2021-04-18 23:51:28 bitdex joins (~bitdex@gateway/tor-sasl/bitdex)
2021-04-18 23:51:34 <lechner> why are they used in JSON instances, please?
2021-04-18 23:51:41 <lechner> and how
2021-04-18 23:51:59 <koz_> lechner: FromJSON has an effect - the Parser effect, to be exact.
2021-04-18 23:52:04 × fiedlr quits (~fiedlr@83.148.33.254) (Remote host closed the connection)
2021-04-18 23:52:13 × mnrmnaugh quits (~mnrmnaugh@unaffiliated/mnrmnaugh) (Ping timeout: 260 seconds)
2021-04-18 23:52:34 <koz_> So the idea is that when you write a FromJSON instance, you work inside that effect, and that allows you to compose Parsers in various ways, by operating on 'what they would parse if they succeeded'.
2021-04-18 23:52:39 × ph88 quits (~ph88@2a02:8109:9e00:7e5c:d5ef:86b3:afc4:9258) (Ping timeout: 260 seconds)
2021-04-18 23:52:40 fiedlr joins (~fiedlr@83.148.33.254)
2021-04-18 23:52:52 <Axman6> PArser is just another 'f' , a.k.a, a functor, and an applicative. if you trun :info PArser in ghic, you'll see it has instances for Functor, Applicative and Monad
2021-04-18 23:52:53 <lechner> but when do i use which? the example has both
2021-04-18 23:53:01 <koz_> What example?
2021-04-18 23:53:10 <Axman6> the example has both of what?
2021-04-18 23:53:21 <lechner> writing instances by hand https://hackage.haskell.org/package/aeson-1.5.6.0/docs/Data-Aeson.html#g:2
2021-04-18 23:53:49 <koz_> lechner: withObject is a helper.
2021-04-18 23:54:00 <koz_> The $ there has precisely 0 to do with JSON.
2021-04-18 23:54:13 <Clint> lechner: until you understand it, just remember that <$> is the first one and everything else after that is <*>
2021-04-18 23:54:21 <koz_> The part that uses the Parser effect is Person <$> v .: "name <*> v .: "age"
2021-04-18 23:56:06 <lechner> it's a learning curve, but boy do i love haskell!
2021-04-18 23:56:50 × fiedlr quits (~fiedlr@83.148.33.254) (Ping timeout: 246 seconds)
2021-04-18 23:57:15 nineonine joins (~nineonine@2604:3d08:7785:9600:68a6:8c79:2caf:5ce4)
2021-04-18 23:59:10 <Axman6> You'll pretty soon realise this pattern comes up _everywhere_
2021-04-19 00:00:07 × atk quits (~Arch-TK@ircpuzzles/staff/Arch-TK) (Quit: Well this is unexpected.)
2021-04-19 00:00:12 <Axman6> for loops? Usually just applicatives. Null checks? Just applicatives a lot of the time too. passing around some config? Applicatives too
2021-04-19 00:00:29 atk joins (~Arch-TK@ircpuzzles/staff/Arch-TK)
2021-04-19 00:00:43 <Axman6> erry day Immapplicative
2021-04-19 00:01:45 <lechner> thanks everyone for your help!
2021-04-19 00:01:52 × nineonine quits (~nineonine@2604:3d08:7785:9600:68a6:8c79:2caf:5ce4) (Ping timeout: 258 seconds)
2021-04-19 00:01:55 <Axman6> lechner: also, for your second Haskell program, you're doing quite well. No haskeller would have any problems reading that
2021-04-19 00:02:01 × jess quits (jess@freenode/staff/jess) (Quit: Lost terminal)
2021-04-19 00:02:01 <Axman6> so nice work
2021-04-19 00:02:27 jess joins (jess@freenode/staff/jess)
2021-04-19 00:02:29 <koz_> Yeah, and you've definitely not picked the easiest second thing to write.
2021-04-19 00:02:35 <koz_> So definitely nice work.
2021-04-19 00:03:03 mnrmnaugh joins (~mnrmnaugh@unaffiliated/mnrmnaugh)
2021-04-19 00:04:10 <lechner> please let me say that i also like your helpful channel, and the friendly tone eround here.
2021-04-19 00:04:25 ddellacosta joins (~ddellacos@86.106.143.10)
2021-04-19 00:04:33 <Axman6> Thanks for being more flexible than... some others :)
2021-04-19 00:04:55 <koz_> lechner: We try.
2021-04-19 00:05:20 <lechner> one day i'll muster the courage to drop Perl and JavaScript everywhere
2021-04-19 00:05:34 <Axman6> D:
2021-04-19 00:08:13 <Axman6> well, learn enough haskell, and you can make it look like Perl. using lens's Control.Lens.Operators makes that even easier
2021-04-19 00:08:46 × ddellacosta quits (~ddellacos@86.106.143.10) (Ping timeout: 252 seconds)
2021-04-19 00:10:24 <lechner> i watched a talk about lenses but that was totally above my my pay grade. i just worked my way through Hutton's tome but like "What I Wish I Knew ..." a lot better, plus of course "Learn you a Good ..." and a few others
2021-04-19 00:11:39 <koz_> Typeclassopedia is also essential IMHO.
2021-04-19 00:11:42 × falafel quits (~falafel@pool-96-255-70-50.washdc.fios.verizon.net) (Ping timeout: 252 seconds)
2021-04-19 00:11:49 × Tuplanolla quits (~Tuplanoll@91-159-68-239.elisa-laajakaista.fi) (Quit: Leaving.)
2021-04-19 00:12:13 <lechner> yeah, it's just a bit steep for the uninitiated
2021-04-19 00:13:14 <lechner> hey, this program takes tasks from AMQP, but execution can take an hour or more. when using a 30 second heartbeat, do i have to use a special, event-loop aware way to fork programs?
2021-04-19 00:17:38 × star_cloud quits (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com) (Ping timeout: 240 seconds)
2021-04-19 00:23:21 fiedlr joins (~fiedlr@83.148.33.254)
2021-04-19 00:23:39 × lambdaman quits (~lambdaman@s66-183-152-156.bc.hsia.telus.net) (Remote host closed the connection)
2021-04-19 00:24:56 philderbeast joins (~textual@bras-base-vldvpq5901w-grc-06-184-144-244-252.dsl.bell.ca)
2021-04-19 00:25:06 × heatsink quits (~heatsink@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2021-04-19 00:26:29 star_cloud joins (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com)
2021-04-19 00:26:44 <Axman6> lechner: you could use threads
2021-04-19 00:27:04 <geekosaur> threads and forkProcess don't mix
2021-04-19 00:27:27 <geekosaur> well, you can do it but expect problems
2021-04-19 00:27:57 × bitdex quits (~bitdex@gateway/tor-sasl/bitdex) (Ping timeout: 240 seconds)
2021-04-19 00:28:32 <geekosaur> since other threads may have something locked but won't be replicated in the subprocess, leaving it with random things (such as Handles) locked and no way to unlock them
2021-04-19 00:28:56 <Axman6> I've never needed to fork haskell programs, threads give me everything I've needed
2021-04-19 00:29:02 <lechner> do i have to use threads when enabling the heartbeat in Network.AMQP, or does the driver send the heartbeat anyway?
2021-04-19 00:29:04 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-04-19 00:29:28 <Axman6> you'd have to look that up, get some experience reading some HAskell library code
2021-04-19 00:29:37 <lechner> yeah
2021-04-19 00:30:06 <lechner> hackage is the best place for online reading?
2021-04-19 00:30:12 <Axman6> sure
2021-04-19 00:30:51 bitdex joins (~bitdex@gateway/tor-sasl/bitdex)
2021-04-19 00:31:12 × olligobber quits (olligobber@gateway/vpn/privateinternetaccess/olligobber) (Ping timeout: 240 seconds)
2021-04-19 00:33:23 × safinaskar quits (6dfc5a88@109-252-90-136.nat.spd-mgts.ru) (Ping timeout: 240 seconds)
2021-04-19 00:36:03 × ericsagnes quits (~ericsagne@2405:6580:0:5100:26cf:eb6d:4a80:182c) (Ping timeout: 260 seconds)
2021-04-19 00:37:20 nineonine joins (~nineonine@2604:3d08:7785:9600:68a6:8c79:2caf:5ce4)
2021-04-19 00:39:30 × nineonine quits (~nineonine@2604:3d08:7785:9600:68a6:8c79:2caf:5ce4) (Remote host closed the connection)

All times are in UTC.