Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-03-21 11:56:20 <curl> better than (f (g x)) though
2021-03-21 11:56:24 <Franciman> what do yo uuse instead of $ ?
2021-03-21 11:56:26 drbean joins (~drbean@TC210-63-209-99.static.apol.com.tw)
2021-03-21 11:56:34 <Franciman> how to reduce its usage?
2021-03-21 11:56:52 <curl> ((f . g) x)
2021-03-21 11:56:57 <curl> which i think is worse
2021-03-21 11:57:09 <curl> the $ go to .
2021-03-21 11:58:11 <curl> ((f . g . h) x) vs (f $ g $ h x)
2021-03-21 11:59:06 <haskell_newbie> hi i m new on channel this is my first experience on irc
2021-03-21 11:59:49 <curl> less internal parens and the precidence of $ or . nicely partitions up expressions, again no parens needed
2021-03-21 12:00:34 <curl> ((f . g x . h) y) vs (f $ g x $ h y)
2021-03-21 12:01:59 <curl> the version with dot, the reader notionally imagines function concatenation
2021-03-21 12:02:17 <curl> the version with the $ the reader has to reduce the expression from the right hand side
2021-03-21 12:02:39 <curl> which is more like what nested parens would mean most obviously
2021-03-21 12:02:54 <curl> function composition*
2021-03-21 12:03:26 × zleap quits (~zleap@185.163.110.108) (Remote host closed the connection)
2021-03-21 12:04:04 <curl> (f (g x $ h y) z)
2021-03-21 12:04:31 <curl> the dollars nicely revert to parens when needed
2021-03-21 12:04:46 <curl> whats going on with the dot version when f takes 2 arguments?
2021-03-21 12:05:03 <curl> you would have to use flip to do the "pointless" version with the dots
2021-03-21 12:06:47 × LKoen quits (~LKoen@194.250.88.92.rev.sfr.net) (Remote host closed the connection)
2021-03-21 12:07:35 <curl> ((flip f z . g x . h) y)
2021-03-21 12:07:38 <curl> which i think is worse
2021-03-21 12:15:33 __monty__ joins (~toonn@unaffiliated/toonn)
2021-03-21 12:15:48 <hololeap> \x y z -> f (g x $ h y) z) === \x y -> f (g x $ h y) === \x -> f . g x . h
2021-03-21 12:16:40 <hololeap> let doThing x = (f . g x . h) in doThing x y z
2021-03-21 12:16:50 <hololeap> or some such
2021-03-21 12:16:59 <Logio> given the choice, I'll always prefer function composition to $
2021-03-21 12:17:40 <Logio> feels like it's easier to spot patterns and generalize your code
2021-03-21 12:18:57 × tsaka__ quits (~torstein@ppp-94-65-45-45.home.otenet.gr) (Quit: Konversation terminated!)
2021-03-21 12:19:03 <ski> hello haskell_newbie
2021-03-21 12:19:12 tsaka__ joins (~torstein@ppp-94-65-45-45.home.otenet.gr)
2021-03-21 12:19:27 spake joins (~spake@185.204.1.185)
2021-03-21 12:19:35 <hololeap> sometimes it makes sense to keep things explicit, especially when composing functions that take more than one argument
2021-03-21 12:19:40 <ski> curl : obviously the last one is worse
2021-03-21 12:20:12 <ski> haskell_newbie : if you have any (Haskell-related) question or topic, feel free to chat up
2021-03-21 12:20:46 <ski> nothing wrong with `f (g x (h y))' or `f (g x (h y)) z'
2021-03-21 12:21:19 <ski> i normally prefer `(f . g x . h) y' over `f . g x . h $ y' over `f $ g x $ h y'
2021-03-21 12:21:48 × shad0w_ quits (a0ca254d@160.202.37.77) (Quit: Connection closed)
2021-03-21 12:22:24 <ski> the "pointless" style is jokingly ("ha ha, only serious") named like that, as a reminder (or warning), that it's quite possible to take it too far
2021-03-21 12:23:16 <hololeap> ski: isn't there something about inlining rules where if you use `doThing x y z = f (g x (h y)) z' it won't be able to inline as easily?
2021-03-21 12:23:47 <ski> inline what ? `doThing' or `f',`g',`h' ?
2021-03-21 12:23:56 <haskell_newbie> thank you so much ski I think my message did not appear there something went wrong. I'll. thanks again :)
2021-03-21 12:23:58 <hololeap> doThing
2021-03-21 12:24:24 <ski> haskell_newbie : people were just caught up a bit, in a conversation :)
2021-03-21 12:24:42 <haskell_newbie> :)
2021-03-21 12:25:01 <ski> iirc, with `doThing x y z = ..x..y..z..', it'll only inline, if `doThing' is fully applied (saturated application)
2021-03-21 12:26:03 <ski> haskell_newbie : do you have any learning material to look at ? beginner questions (but also more advanced ones) are welcome in here, if you get any. (both practical and theoretical ones)
2021-03-21 12:26:09 × tsaka__ quits (~torstein@ppp-94-65-45-45.home.otenet.gr) (Ping timeout: 256 seconds)
2021-03-21 12:28:07 dementorr joins (5678f228@86.120.242.40)
2021-03-21 12:28:13 <hololeap> ski: right, and will `doThing x = f . g x . h' be able to inline with application of one, two, or three variables? if so, that's a "point" to "pointless" :)
2021-03-21 12:30:48 <dementorr> Hello! Is there a way to use global state in IO Monad? I know this not usually the way to do it, but I am spawning a program from a function, and I would like to save the handle in a Map. This function is called by other code that I don't have access to, and I want to do more things with the handles. Link: https://pastebin.com/ZsYsnSfB
2021-03-21 12:31:18 <ski> hololeap : yes
2021-03-21 12:32:03 <ski> @wiki Top level mutable state
2021-03-21 12:32:03 <lambdabot> https://wiki.haskell.org/Top_level_mutable_state
2021-03-21 12:32:58 <ski> but usually it's better to pass around the state or config/environment. scales better, if you're having multiple threads or whatever
2021-03-21 12:33:31 Vadrigar joins (~Vadrigar@ip5b417208.dynamic.kabel-deutschland.de)
2021-03-21 12:33:54 <ski> @wiki Global variables
2021-03-21 12:33:54 <lambdabot> https://wiki.haskell.org/Global_variables
2021-03-21 12:34:39 <ski> often, `ReaderT MyConfig IO' is used. implicit parameters could also be used
2021-03-21 12:35:42 <ski> (`MyConfig' could be a `Handle' or an `IORef T' or some other reference to a mutable location, which then allows update, and not only distribution (and possible local change) of an environment/config)
2021-03-21 12:36:29 <hololeap> dementorr: i don't see why you need global state for that
2021-03-21 12:37:26 × gitgoood quits (~gitgood@80-44-12-39.dynamic.dsl.as9105.com) (Read error: Connection reset by peer)
2021-03-21 12:38:01 <ski> dementorr : did you mean to have a space after the `program' part ?
2021-03-21 12:38:43 <hololeap> creator :: Int -> IntMap Handle -> IO (IntMap Handle)
2021-03-21 12:39:08 × Vadrigar quits (~Vadrigar@ip5b417208.dynamic.kabel-deutschland.de) (Ping timeout: 260 seconds)
2021-03-21 12:39:22 <ski> anyway, it would be possible to have `state :: IORef (Map Int Handle)' (using the trick i referenced before). but it's most likely better to just pass around the `Map Int Handle' (or possibly an `IORef (Map Int Handle)') to the functions that need it
2021-03-21 12:40:47 <dementorr> ski, hololeap: Yeah, there is a space there. The problem is that I can't modify the function's signature. It has to be Int -> IO Handle. I just want to save the value(s) before I return them, and use later like in (https://pastebin.com/1hjARUTw)  say I don't want to print them right away, maybe later...
2021-03-21 12:41:13 × zerok quits (~user@101.50.108.120) (Quit: WeeChat 3.0)
2021-03-21 12:41:31 z0k joins (~user@101.50.108.120)
2021-03-21 12:43:06 <ski> dementorr : there is no space put in the string, in your pasted code
2021-03-21 12:43:15 <hololeap> dementorr: so you need `creator` to have that signature, but you can modify its contents?
2021-03-21 12:43:32 <ski> why can't you modify it ?
2021-03-21 12:43:37 <dementorr> ski: It is in the latest :)
2021-03-21 12:44:06 <ski> who's using `creator' ?
2021-03-21 12:44:20 <ski> are you passing `creator' as a callback argument to another function, maybe ?
2021-03-21 12:44:29 <ski> (the latest ?)
2021-03-21 12:45:06 <dementorr> hololeap: It is used by another module. That module says it need a function that has the signature Int -> IO Handle, and it will store the handles and use them later. Now I want to be able to access them for other things.
2021-03-21 12:45:13 <dementorr> https://pastebin.com/1hjARUTw
2021-03-21 12:45:21 <dementorr> Oh
2021-03-21 12:45:29 <dementorr> there were two "./programs"
2021-03-21 12:45:38 <dementorr> Yeah there should be a space there twoo
2021-03-21 12:45:51 <ski> in your first paste, there was no space at either site
2021-03-21 12:45:57 <dementorr> Yes I know :(
2021-03-21 12:46:18 <dementorr> So it is a callback
2021-03-21 12:47:35 × zaquest quits (~notzaques@5.128.210.178) (Quit: Leaving)
2021-03-21 12:47:52 <hololeap> dementorr: so you want to secretly store the Handles when `creator` is run so you can access them later? this has a funky smell to me.
2021-03-21 12:48:15 <dementorr> Yep!! That's about right :d
2021-03-21 12:49:10 <hololeap> part of the problem is that "later" is not well defined. if something external is calling `creator`, how are you going to call something else afterward?
2021-03-21 12:49:14 <dementorr> I can't do it in another way since the state of the module is not exported and there aren't any ways to use get on the state
2021-03-21 12:49:23 × Pickchea quits (~private@unaffiliated/pickchea) (Ping timeout: 256 seconds)
2021-03-21 12:49:26 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 256 seconds)
2021-03-21 12:49:29 zaquest joins (~notzaques@5.128.210.178)
2021-03-21 12:49:56 <ski> dementorr : if another function expects to be passed `creator' as a callback argument, then there is no problem. simply pass a partially applied `creator' to it, partially applied to the `IntMap Handle' (or `IORef (IntMap Handle)', if you want mutation in the callback, or want to be able to get the latest version, which i suppose you do)
2021-03-21 12:50:52 peanut_ joins (~peanut@2a02:8388:a101:2600:52d3:48bc:f38c:73e)
2021-03-21 12:51:06 <ski> iow, you could have `creator :: IntMap Handle -> Int -> IO Handle' or `creator :: IORef (IntMap Handle) -> Int -> IO Handle'. or perhaps `creator :: IORef (IntMap Handle) -> IO (Int -> IO Handle)', even
2021-03-21 12:52:09 <ski> (the `foo :: Blah -> IO (Bleh -> IO Bloh)' can be useful, if you want `foo' to do some I/O, or allocate some mutable state, that the computed function could reference)
2021-03-21 12:53:11 Vadrigar joins (~Vadrigar@ip5b417208.dynamic.kabel-deutschland.de)
2021-03-21 12:53:34 <dementorr> Okay I think I need something like "creator :: IORef (IntMap Handle) -> Int -> IO Handle"... so what I should do is:
2021-03-21 12:53:34 <dementorr> 1) define a global map of type myMap :: IORef (IntMap Handle)

All times are in UTC.