Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2020-11-22 04:21:59 <dsal> > (+) <$> Right 11 <*> Right 2
2020-11-22 04:22:02 <lambdabot> Right 13
2020-11-22 04:22:02 futuba joins (2fe3e53b@047-227-229-059.res.spectrum.com)
2020-11-22 04:22:04 <dsal> > (+) <$> Left "boo" <*> Right 2
2020-11-22 04:22:06 <lambdabot> Left "boo"
2020-11-22 04:22:19 <koz_> The way I like to think about it is this.
2020-11-22 04:22:29 <koz_> If you have 'f x y', you're computing in a 'pure' context.
2020-11-22 04:22:42 <koz_> But what if x and y have effects too?
2020-11-22 04:22:50 <koz_> For example, IO, or Maybe, or w/e?
2020-11-22 04:22:53 <koz_> We wanna compute there too.
2020-11-22 04:23:07 <koz_> So in that case, we can use the Applicative nature of (many) effects, and instead write
2020-11-22 04:23:11 <koz_> f <$> x <*> y
2020-11-22 04:23:14 <dsal> :t (+) <$> pure 1 <*> pure 2
2020-11-22 04:23:15 <lambdabot> (Applicative f, Num b) => f b
2020-11-22 04:23:55 <koz_> A way to make this even more clear:
2020-11-22 04:23:58 <koz_> :t ($)
2020-11-22 04:24:00 <lambdabot> (a -> b) -> a -> b
2020-11-22 04:24:03 <koz_> :t <*>
2020-11-22 04:24:05 <lambdabot> error: parse error on input ‘<*>’
2020-11-22 04:24:10 <koz_> :t (<*>)
2020-11-22 04:24:11 <lambdabot> Applicative f => f (a -> b) -> f a -> f b
2020-11-22 04:24:12 vollenweider joins (~vollenwei@4e69b241.skybroadband.com)
2020-11-22 04:24:17 <koz_> Notice how those are quite similar?
2020-11-22 04:24:28 <futuba> yeah
2020-11-22 04:24:33 <futuba> hm interesting
2020-11-22 04:24:39 <dsal> :t (<$>) -- for completeness
2020-11-22 04:24:40 <lambdabot> Functor f => (a -> b) -> f a -> f b
2020-11-22 04:25:06 <koz_> In this case, it's best vieweed as having the type '(Functor f) => (a -> b) -> (f a -> f b)
2020-11-22 04:25:08 <koz_> '
2020-11-22 04:25:28 <koz_> (i.e. you are 'promoting' a function that works on non-effectful values to a function that works on effectful ones)
2020-11-22 04:25:47 <koz_> You will also note that (<$>) is fmap.
2020-11-22 04:26:00 <koz_> (we have it there to make stuff of this form easier to write)
2020-11-22 04:26:13 conal joins (~conal@198.8.81.205)
2020-11-22 04:26:21 × conal quits (~conal@198.8.81.205) (Client Quit)
2020-11-22 04:26:48 <futuba> right
2020-11-22 04:26:49 <futuba> ok
2020-11-22 04:27:15 conal joins (~conal@198.8.81.205)
2020-11-22 04:27:20 merijn joins (~merijn@83-160-49-249.ip.xs4all.nl)
2020-11-22 04:27:29 × conal quits (~conal@198.8.81.205) (Client Quit)
2020-11-22 04:27:36 <koz_> Also work noting - any Applicative is also a Functor.
2020-11-22 04:27:40 <koz_> s/work/worth/
2020-11-22 04:28:06 <futuba> right
2020-11-22 04:28:16 <futuba> another question, what is the point of using >>?
2020-11-22 04:28:30 <koz_> futuba: For that, we can compare with >>=
2020-11-22 04:28:33 <koz_> :t (>>=)
2020-11-22 04:28:34 <lambdabot> Monad m => m a -> (a -> m b) -> m b
2020-11-22 04:28:38 <koz_> :t (>>)
2020-11-22 04:28:39 <lambdabot> Monad m => m a -> m b -> m b
2020-11-22 04:28:44 <koz_> What's the difference there?
2020-11-22 04:28:49 <futuba> there's no a
2020-11-22 04:29:05 <koz_> Precisely - we don't use the 'a' to produce the m b.
2020-11-22 04:29:11 <koz_> However, 'm a' still has an effect.
2020-11-22 04:29:26 <koz_> So when we use >>, both _effects_ still occur, but we just ignore the _value_ from the first one.
2020-11-22 04:29:35 <futuba> ohh
2020-11-22 04:29:36 <koz_> (in fact, you can define >> using >>=)
2020-11-22 04:29:45 <futuba> but for Maybe and List monad, there's no point right?
2020-11-22 04:29:51 <koz_> Also, given the nature of your questions: have you read the Typeclassopedia?
2020-11-22 04:29:56 <futuba> I have not
2020-11-22 04:29:58 <koz_> For 'Maybe', there very much _is_ a point.
2020-11-22 04:30:04 <futuba> but I am aware of the typeclass defiitions
2020-11-22 04:30:12 <koz_> I would recommend that you read the Typeclassopedia.
2020-11-22 04:30:18 <futuba> I think I saw it and found it too scary :))
2020-11-22 04:30:22 <koz_> A lot of your questions are answered by it, in great detail.
2020-11-22 04:30:25 <koz_> Yeah, it's not a light read.
2020-11-22 04:30:31 <koz_> But patience and time gets you everywhere.
2020-11-22 04:30:49 <futuba> what's the best way to get practice with these things?
2020-11-22 04:31:41 <futuba> i feel like typeclassopedia will get me the necessary theory, but i kind of feel like i need to think through code and stuff to really understand them
2020-11-22 04:31:41 <koz_> futuba: Write more Haskell.
2020-11-22 04:31:47 <futuba> yeah, but how :)
2020-11-22 04:31:53 <koz_> Think of a thing you wanna make.
2020-11-22 04:31:55 <koz_> Then write that.
2020-11-22 04:32:02 <koz_> Do the exercises the Typeclassopedia comes with.
2020-11-22 04:32:08 <koz_> (all, or nearly all, of them are code)
2020-11-22 04:32:18 <koz_> Ditto the exercises you asked about earlier.
2020-11-22 04:33:25 × vicfred quits (~vicfred@unaffiliated/vicfred) (Quit: Leaving)
2020-11-22 04:35:27 Saukk joins (~Saukk@2001:998:f9:2914:1c59:9bb5:b94c:4)
2020-11-22 04:41:04 whatisRT joins (~whatisRT@2002:5b41:6a33:0:1094:8ebf:d3e9:e277)
2020-11-22 04:45:10 × da39a3ee5e6b4b0d quits (~da39a3ee5@2403:6200:8876:6c06:8500:38e7:4522:4d5) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-11-22 04:48:37 da39a3ee5e6b4b0d joins (~da39a3ee5@2403:6200:8876:6c06:8500:38e7:4522:4d5)
2020-11-22 04:55:32 × sszark quits (~sszark@h-213-180.A392.priv.bahnhof.se) (Remote host closed the connection)
2020-11-22 05:00:02 × _Alleria quits (~AllahuAkb@2604:2000:1484:26:b060:c081:3394:137) (Ping timeout: 260 seconds)
2020-11-22 05:01:31 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 256 seconds)
2020-11-22 05:02:43 Alleria_ joins (~AllahuAkb@2604:2000:1484:26:b060:c081:3394:137)
2020-11-22 05:10:06 falafel__ joins (~falafel@2601:547:1303:b30:7811:313f:d0f3:f9f4)
2020-11-22 05:11:30 Jonkimi727406120 joins (~Jonkimi@113.87.161.66)
2020-11-22 05:12:45 blendux joins (~blendux@99-33-66-185.lightspeed.yrlnca.sbcglobal.net)
2020-11-22 05:13:59 blendux parts (~blendux@99-33-66-185.lightspeed.yrlnca.sbcglobal.net) ()
2020-11-22 05:14:08 × solonarv quits (~solonarv@astrasbourg-653-1-156-4.w90-6.abo.wanadoo.fr) (Ping timeout: 272 seconds)
2020-11-22 05:18:08 × heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2020-11-22 05:18:25 × Gurkenglas quits (~Gurkengla@unaffiliated/gurkenglas) (Ping timeout: 240 seconds)
2020-11-22 05:24:47 × Sarma quits (~Amras@unaffiliated/amras0000) (Ping timeout: 272 seconds)
2020-11-22 05:24:50 × whatisRT quits (~whatisRT@2002:5b41:6a33:0:1094:8ebf:d3e9:e277) (Read error: Connection reset by peer)
2020-11-22 05:27:56 × redmp quits (~redmp@mobile-166-137-178-152.mycingular.net) (Ping timeout: 240 seconds)
2020-11-22 05:29:37 falafel__ is now known as falafel
2020-11-22 05:30:08 × futuba quits (2fe3e53b@047-227-229-059.res.spectrum.com) (Remote host closed the connection)
2020-11-22 05:31:21 hlisp joins (~hlisp@114.246.35.11)
2020-11-22 05:31:29 × hlisp quits (~hlisp@114.246.35.11) (Read error: Connection reset by peer)
2020-11-22 05:32:43 × shailangsa quits (~shailangs@host86-186-136-90.range86-186.btcentralplus.com) (Ping timeout: 260 seconds)
2020-11-22 05:34:57 × texasmynsted quits (~texasmyns@212.102.45.109) (Remote host closed the connection)
2020-11-22 05:35:53 merijn joins (~merijn@83-160-49-249.ip.xs4all.nl)

All times are in UTC.