Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,804,018 events total
2021-08-08 06:40:05 <tomsmeding> yeah, where F = (->) a
2021-08-08 06:40:11 <tomsmeding> so F b = (->) a b = a -> b
2021-08-08 06:40:12 <euouae> Alright
2021-08-08 06:40:21 <euouae> Great, thank you
2021-08-08 06:41:41 <euouae> am I supposed to be able to think of stuff like (,) <$> f <*> g
2021-08-08 06:41:49 <euouae> or is it something someone thought once and now it's an idiom?
2021-08-08 06:42:18 <Cajun> ive found that i like to use applicatives when monads are overkill
2021-08-08 06:42:26 endlesseditions joins (~endlessed@205.220.252.162)
2021-08-08 06:42:30 <tomsmeding> you will be able to think of that, when you've worked with applicatives long enough :)
2021-08-08 06:42:42 <Cajun> but remember that <$> is just fmap, dont be afraid of the scary symbols :)
2021-08-08 06:43:29 <tomsmeding> in particular, knowing that ((->) a) is just the Reader monad, helps in figuring out how this works :p
2021-08-08 06:43:44 <euouae> Yeah I definitely had entirely forgotten about ((->) a)
2021-08-08 06:43:52 <euouae> which I think I've only heard in passing and not sure where from
2021-08-08 06:44:31 <Cajun> its strange going from thinking (->) is a language implemented thing to realizing its defined within the language with instances
2021-08-08 06:45:04 <Cajun> that kinda hurt my head when the exercise of "write the functor, applicative, and monad instances of (->)" came up
2021-08-08 06:45:41 <tomsmeding> (well, (->) is really still a built-in thing at the end; it's just "methods attached to it" (instances) that are library-defined)
2021-08-08 06:45:44 <tomsmeding> but yeah
2021-08-08 06:46:15 <tomsmeding> wait until you learn Agda and start defining mixfix operators
2021-08-08 06:46:52 <Cajun> ive heard agda lets you go down the rabbit hole of the stuff above kinds... scary
2021-08-08 06:48:41 <euouae> even trying on paper I still can't understand (,) <$> f
2021-08-08 06:49:13 <euouae> at least not for a general f :: a -> b
2021-08-08 06:49:19 <euouae> which I'm not even sure if exists
2021-08-08 06:49:46 <Cajun> i would say try with something other than (,) as that takes both an `a` and `b`
2021-08-08 06:50:23 <euouae> no wait a moment
2021-08-08 06:50:27 × img quits (~img@user/img) (Quit: ZNC 1.8.2 - https://znc.in)
2021-08-08 06:50:30 <euouae> if we think of the functor as ((->) a)
2021-08-08 06:50:51 <euouae> then the signature (a -> b) -> F a -> F b of <$> simply says to post-compose F a with (a -> b)
2021-08-08 06:51:05 <euouae> in other words g <$> f is the same as g(f(x))
2021-08-08 06:51:31 <tomsmeding> https://hackage.haskell.org/package/base-4.14.0.0/docs/src/GHC.Base.html#line-969
2021-08-08 06:51:53 img joins (~img@user/img)
2021-08-08 06:52:49 <euouae> so in other words, to post-compose f x with (,) giving (f x, )
2021-08-08 06:52:51 <Cajun> im not sure thats entirely true euouae . thats implying `f :: f a`
2021-08-08 06:53:08 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 258 seconds)
2021-08-08 06:53:10 <Cajun> `(<$>) :: Functor f => (a -> b) -> f a -> f b`
2021-08-08 06:55:15 <Cajun> `g <$> f` is saying youre `fmap` 'ing `g` over `f`
2021-08-08 06:55:27 <Cajun> or rather `pure g` applied to `f`
2021-08-08 06:55:56 <tomsmeding> ("applied" in the sense of <*> or ap)
2021-08-08 06:56:09 <euouae> whereas <*> is composition to the second argument, i.e. if you have `f x y` and `g z` you can write `f <*> g` to mean the map `z, y -> f (g y) z`
2021-08-08 06:56:49 <euouae> sorry I meant `f y (g z)`
2021-08-08 06:57:05 <tomsmeding> isn't it `\z -> f z (g z)`
2021-08-08 06:57:26 <tomsmeding> (<*>) :: (a -> b) -> (z -> a) -> (z -> b)
2021-08-08 06:57:37 <tomsmeding> um no
2021-08-08 06:57:38 <tomsmeding> that's fmap
2021-08-08 06:57:40 <euouae> It's F (a -> b) -> F a -> F b, which means F is consuming 1 argument ((->) c)
2021-08-08 06:57:47 <tomsmeding> (<*>) :: (z -> a -> b) -> (z -> a) -> (z -> b)
2021-08-08 06:58:02 <tomsmeding> where of course F = (->) z
2021-08-08 06:58:27 × pe200012 quits (~pe200012@113.105.10.33) (Quit: Konversation terminated!)
2021-08-08 06:58:27 <Cajun> it may be better to just not use <$> when learning applicatives, it may be confusing you a bit
2021-08-08 06:59:46 <euouae> think of F (a -> b) as a function f that takes 2 arguments
2021-08-08 06:59:58 pe200012 joins (~pe200012@113.105.10.33)
2021-08-08 06:59:58 <euouae> and F a as a function g that takes 1 argument
2021-08-08 07:00:19 Tuplanolla joins (~Tuplanoll@91-159-69-50.elisa-laajakaista.fi)
2021-08-08 07:00:20 <euouae> so f <*> g x === f x (g x)
2021-08-08 07:00:24 <euouae> Like you said tomsmeding
2021-08-08 07:00:51 <tomsmeding> note, f <*> g x is not the same as (f <*> g) x
2021-08-08 07:00:58 <tomsmeding> apart from that, yes :)
2021-08-08 07:00:58 <Drew[m]1> If just learning applicatives was the goal I wouldn't start with the reader function applicative IMO, unless learning the reader applicative was the specific goal
2021-08-08 07:01:12 <euouae> My goal is not learning applicative
2021-08-08 07:01:21 <euouae> I was reading an example from reactive-banana that used this trick
2021-08-08 07:01:28 <euouae> https://github.com/HeinrichApfelmus/reactive-banana/blob/master/reactive-banana/doc/examples/SlotMachine.hs#L49
2021-08-08 07:02:22 <Cajun> applicatives are definitely something to pick up
2021-08-08 07:02:36 × cheater quits (~Username@user/cheater) (Ping timeout: 256 seconds)
2021-08-08 07:02:50 <Cajun> imo its as important as learning functors and monads as they all share similar aspects
2021-08-08 07:03:11 <euouae> Do you mean, study the instances of applicative?
2021-08-08 07:03:21 <euouae> or the interface
2021-08-08 07:04:04 <tomsmeding> heh that makeSources function could do with a type annotation perhaps
2021-08-08 07:04:45 <Cajun> i mean in the sense of learning anything in the language. just as you learn functors and monads, applicatives should be picked up too
2021-08-08 07:04:59 <Drew[m]1> euouae: If the functor wasn't reader and was instead a list, would you get `f <$> x <*> y`?
2021-08-08 07:04:59 <Drew[m]1> For example `[(+), (*)] <$> [1,2] <*> [1, 10, 100]`
2021-08-08 07:05:40 <tomsmeding> list bad example, both the normal list applicative instance and ZipList are sensible :p
2021-08-08 07:05:52 <Cajun> the chapter "functors, applicatives, and monads" in Programming in Haskell would probably get you up to speed, and its also why i say you shouldnt use <$> until youre comfortable with `pure <*>` instead
2021-08-08 07:05:53 <tomsmeding> but yeah
2021-08-08 07:05:58 × endlesseditions quits (~endlessed@205.220.252.162) (Quit: Textual IRC Client: www.textualapp.com)
2021-08-08 07:06:14 <Drew[m]1> Or `Just (+) <$> Just 2 <*> Just 5`
2021-08-08 07:06:15 <euouae> Drew[m]1: I would need to know the instances of these things for the list and I don't know them and it's not important right now either :P
2021-08-08 07:07:09 <euouae> tomsmeding: Where is newAddHandler coming from? I don't see it anywhere defined in the source
2021-08-08 07:07:21 <euouae> It's not imported nor defined
2021-08-08 07:07:22 <Cajun> applicative instance for list is cartesian product iirc
2021-08-08 07:07:37 <tomsmeding> euouae: presumably here? https://hackage.haskell.org/package/reactive-banana-1.2.1.0/docs/Control-Event-Handler.html#v:newAddHandler
2021-08-08 07:07:52 <Drew[m]1> Oops my list example was bad, wasn't it
2021-08-08 07:07:56 <tomsmeding> Cajun: yeah
2021-08-08 07:07:59 <euouae> oh Interesting
2021-08-08 07:08:32 <Cajun> yes it was Drew[m]1 but all you need to do to fix it is change [(+), (*)] to either (+) or (*)
2021-08-08 07:08:33 <tomsmeding> ( euouae: what I did was go to the hackage page of reactive-banana, type 's', type newAddHandler, press Enter :p )
2021-08-08 07:08:39 <Drew[m]1> Should've been `(+) <$> [1,2] <*> [1, 10, 100]`
2021-08-08 07:08:52 <euouae> tomsmeding: but that module is not imported, how do they use newAddHandler?
2021-08-08 07:09:38 <Cajun> tomsmeding thats a feature!? how did i never know of this
2021-08-08 07:10:01 <tomsmeding> euouae: Reactive.Banana.Frameworks re-exports module Control.Event.Handler
2021-08-08 07:10:12 <tomsmeding> (search for Control.Event.Handler on https://hackage.haskell.org/package/reactive-banana-1.2.1.0/docs/Reactive-Banana-Frameworks.html )
2021-08-08 07:10:21 <euouae> Oooh...
2021-08-08 07:10:26 <tomsmeding> so the applicative here is IO !
2021-08-08 07:11:00 <euouae> not the arrow
2021-08-08 07:11:02 <euouae> ?
2021-08-08 07:11:21 <tomsmeding> nope
2021-08-08 07:11:25 <tomsmeding> newAddHandler :: IO something
2021-08-08 07:11:38 <tomsmeding> so (,) <$> newAddHandler <*> newAddHandler :: IO (something, something)
2021-08-08 07:11:45 <Cajun> oh thats neat
2021-08-08 07:11:47 <Drew[m]1> Cajun: Without knowing the keybinds it can be accessed with the "quick jump" button on the module contents page. That's how I found it.
2021-08-08 07:11:49 <tomsmeding> where something = (AddHandler a, Handler a)
2021-08-08 07:12:14 <Drew[m]1> package contents page I mean

All times are in UTC.