Search Haskell Channel Logs

Friday, February 10, 2017

#haskell channel featuring bollu, hpc, unclechu, pavonia, biglama, Profpatsch, and 13 others.

tsahyt 2017-02-10 01:45:42
biglama: at least I think it's working, http://sprunge.us/QXQT
tsahyt 2017-02-10 01:46:13
everything else is the same as in your code, just changing some imports and the necessary changes to make it work again
hpc 2017-02-10 01:47:46
ondraa: pack . show?
ondraa 2017-02-10 01:48:40
hpc: I was hoping I could avoid the conversion to string in the middle
merijn 2017-02-10 01:49:26
ondraa: https://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text-Lazy-Builder-Int.html ?
phadej 2017-02-10 01:49:37
or text-show
phadej 2017-02-10 01:49:46
anyhow, the performance loss is really neglible
merijn 2017-02-10 01:50:10
phadej: Depends on how many numbers you show ;)
phadej 2017-02-10 01:50:28
merijn: well, then you definitely should use Builder, and not Int -> Text
phadej 2017-02-10 01:51:10
and maybe even ByteString one
hpc 2017-02-10 01:51:59
ondraa: the string never exists in memory all at the same time, it's more of the data definition of a loop in this scenario
lyxia 2017-02-10 01:53:44
_sras_: once you have a Lens you can specialize it to a Getter. Hide the original Lens, export the Getter.
puregreen 2017-02-10 01:54:09
_sras_: afaik there's a flag to generate getters instead of lenses
puregreen 2017-02-10 01:54:34
http://hackage.haskell.org/package/lens-4.15.1/docs/Control-Lens-TH.html#v:generateUpdateableOptics
lyxia 2017-02-10 01:54:55
oh indeed
unclechu 2017-02-10 01:55:04
hey guys, how I can handle closing stdout?
ondraa 2017-02-10 01:56:24
hpc, phadej, merijn: thank you for your help. I am gonna go with pack . show for now. By chance is there some article with comparison of these approaches?
hpc 2017-02-10 01:56:36
unclechu: hClose stdout
puregreen 2017-02-10 01:56:54
I think pack.show is actually fast but my memory might be hazy
DonaldJTrump 2017-02-10 01:57:03
how can i into haskell
DonaldJTrump 2017-02-10 01:57:06
pls help me
unclechu 2017-02-10 01:57:16
hpc: no, i mean, how i can catch when parent of my app closing stdout?
Profpatsch 2017-02-10 01:57:21
Design question:
Profpatsch 2017-02-10 01:57:23
setInnerHTML :: Element -> Text -> Dom ()
Profpatsch 2017-02-10 01:57:29
setInnerHTML :: Text -> Element -> Dom ()
hpc 2017-02-10 01:57:36
hIsEOF or something like that
hpc 2017-02-10 01:57:42
a closed handle is a closed handle
puregreen 2017-02-10 01:58:12
Profpatsch: I'd go with the latter
hpc 2017-02-10 01:58:43
https://hackage.haskell.org/package/base-4.9.1.0/docs/System-IO.html#v:hIsEOF and possibly https://hackage.haskell.org/package/base-4.9.1.0/docs/System-IO.html#v:hIsClosed
unclechu 2017-02-10 01:59:03
hpc: what I'm suppoed to do with it? fork a thread and check by timer interval is it isn't closed?
Profpatsch 2017-02-10 01:59:25
puregreen: The varying elements should be on the right, right?
unclechu 2017-02-10 01:59:38
it would be a horrible way I think
dramforever 2017-02-10 02:00:07
:t modifyIORef
hpc 2017-02-10 02:00:08
unclechu: or check when you read from it
lambdabot 2017-02-10 02:00:10
error:
lambdabot 2017-02-10 02:00:10
• Variable not in scope: modifyIORef
lambdabot 2017-02-10 02:00:10
• Perhaps you meant one of these:
dramforever 2017-02-10 02:00:10
:t modifyMVar
lambdabot 2017-02-10 02:00:13
error: Variable not in scope: modifyMVar
dramforever 2017-02-10 02:00:14
hey
dramforever 2017-02-10 02:00:23
:t Data.IORef.modifyIORef
lambdabot 2017-02-10 02:00:27
GHC.IORef.IORef a -> (a -> a) -> IO ()
puregreen 2017-02-10 02:01:10
Profpatsch: more like "make it easy for people to use"
pavonia 2017-02-10 02:01:25
Is there a single, possibly more generic function for concat . sequence?
puregreen 2017-02-10 02:01:27
e.g. modifyIORef often takes a lambda so it makes sense to make that lambda the last parameter
Profpatsch 2017-02-10 02:01:29
puregreen: And what does that mean for argument order?
phadej 2017-02-10 02:02:01
:t concat . sequence
lambdabot 2017-02-10 02:02:03
(Foldable t, Monad t) => [t a] -> [a]
puregreen 2017-02-10 02:02:06
on the other hand, if you anticipate something like "mapM_ (setInnerHTML "") [e1, e2, e3]" then it would make sense to make text the first argument
Profpatsch 2017-02-10 02:02:44
Hm.
puregreen 2017-02-10 02:02:45
on the third hand, if you anticipate "setInnerHTML e $ "Hello my dear friend! Let me offer you " ++ ..." then the flipped order makes sense
phadej 2017-02-10 02:02:45
:t \xss -> xss ^.. folded . folded
lambdabot 2017-02-10 02:02:48
(Foldable f1, Foldable f) => f (f1 a) -> [a]
phadej 2017-02-10 02:02:57
:t foldMap fold
lambdabot 2017-02-10 02:02:59
(Monoid m, Foldable t1, Foldable t) => t (t1 m) -> m
phadej 2017-02-10 02:03:09
:t foldMap foldMap pure
lambdabot 2017-02-10 02:03:11
(Monoid m, Foldable ((->) m), Foldable t) => t a -> m
phadej 2017-02-10 02:03:15
:t foldMap (foldMap pure)
lambdabot 2017-02-10 02:03:17
(Monoid (f a), Foldable t1, Foldable t, Applicative f) => t (t1 a) -> f a
Profpatsch 2017-02-10 02:03:22
puregreen: For reference, the GHCJS API puts the objects first.
phadej 2017-02-10 02:03:24
näh
unclechu 2017-02-10 02:03:38
hpc: hmmm. I'm actually don't think that `stdout` supposed to be readed at all :) and most important thing is that I really need stop my application when parent died and really don't want wait to some moment to realize like 'whoah, my parent is done long time ago and i'm just wasting cpu time for nothing, well at least i will stop at this moment, better late than never'
Profpatsch 2017-02-10 02:04:13
But that's just because it's mirroring the DOM API; maybe it's better the other way around for an abstraction.
phadej 2017-02-10 02:04:24
pavonia: not sure what you mean, do you want:
phadej 2017-02-10 02:04:29
:t > fmap concat . sequence
lambdabot 2017-02-10 02:04:31
error: parse error on input '>'
phadej 2017-02-10 02:04:33
:t fmap concat . sequence
lambdabot 2017-02-10 02:04:35
(Traversable t, Monad f) => t (f [a]) -> f [a]
puregreen 2017-02-10 02:04:44
if you don't have any clear usecases in mind that you could optimise for, I'd suggest mirroring the DOM API as well, I guess :)
Profpatsch 2017-02-10 02:04:45
Normally my hunch would be to put the arguments that are more "static" for the user more to the left.
Profpatsch 2017-02-10 02:05:27
On the other hand it would be el `setInnerHTML` "foo"
pavonia 2017-02-10 02:05:31
phadej: Without the fmap. Run some actions, collect the results and put them together
phadej 2017-02-10 02:06:20
pavonia: :t concat . sequence
phadej 2017-02-10 02:06:24
:t concat . sequence
lambdabot 2017-02-10 02:06:26
(Foldable t, Monad t) => [t a] -> [a]
puregreen 2017-02-10 02:06:31
Profpatsch: I wouldn't expect the backticked form to be used often, though maybe I'm biased
phadej 2017-02-10 02:07:07
foldable and monad t
puregreen 2017-02-10 02:07:07
it's just that I rarely see backticked forms even when the library authors intended them to be used (with exceptions of `finally`, `div` and `elem`)
phadej 2017-02-10 02:07:10
thjat's suspicious
hpc 2017-02-10 02:07:39
unclechu: actually, another thought, though it's a pretty silly one
phadej 2017-02-10 02:07:42
:t concatMap toList
lambdabot 2017-02-10 02:07:44
error:
lambdabot 2017-02-10 02:07:44
Ambiguous occurrence 'toList'
lambdabot 2017-02-10 02:07:44
It could refer to either 'F.toList',
phadej 2017-02-10 02:07:48
:t concatMap F.toList
pavonia 2017-02-10 02:07:49
phadej: t is Parser in my case, so it doen't need to be a Monad
lambdabot 2017-02-10 02:07:50
(Foldable t1, Foldable t) => t (t1 b) -> [b]
hpc 2017-02-10 02:07:53
unclechu: have a thread that's always pulling data from stdout and stuffing it in a Chan
Profpatsch 2017-02-10 02:08:03
phadej: No, sequence comes from Monad
hpc 2017-02-10 02:08:13
unclechu: the rest of your code consumes from the Chan, and the thread pulling data is always either receiving text or waiting for it to arrive
hpc 2017-02-10 02:08:24
so stdout is always being watched and you can get that eof instantly
phadej 2017-02-10 02:09:03
pavonia: is your Parser `Foldable`, otherwise `concat . sequence` won't type check
phadej 2017-02-10 02:09:06
I doubt
pavonia 2017-02-10 02:11:59
phadej: Hhm, no. And actually you were right, it's concat <$> sequence :S
phadej 2017-02-10 02:13:39
:) but I'm pretty sure there isn't shorter name for that
pavonia 2017-02-10 02:14:41
:t \cs -> concat <$> sequence cs
lambdabot 2017-02-10 02:14:44
(Traversable t, Monad f) => t (f [a]) -> f [a]
phadej 2017-02-10 02:15:30
:t fmap mconcat <$> sequenceA cs
lambdabot 2017-02-10 02:15:33
error:
lambdabot 2017-02-10 02:15:33
• Variable not in scope: cs :: f1 (f [b])
lambdabot 2017-02-10 02:15:33
• Perhaps you meant one of these:
phadej 2017-02-10 02:15:36
:t fmap mconcat . sequenceA
lambdabot 2017-02-10 02:15:38
(Monoid b, Applicative f) => [f b] -> f b
phadej 2017-02-10 02:18:51
:t foldM
lambdabot 2017-02-10 02:18:52
(Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
tsahyt 2017-02-10 02:21:30
is there an example of a Foldable that is not a Functor?
phadej 2017-02-10 02:21:36
Set
tsahyt 2017-02-10 02:21:46
ah right, thanks!
phadej 2017-02-10 02:23:07
pavonia:
phadej 2017-02-10 02:23:12
:t foldM (\x y -> (x <>) <$> y ) mempty
lambdabot 2017-02-10 02:23:14
(Monoid b, Foldable t, Monad m) => t (m b) -> m b
phadej 2017-02-10 02:23:21
might be better, though uglier
pavonia 2017-02-10 02:24:09
Yeah, that's less readable, I'll stick with the other version. Thanks though
merijn 2017-02-10 02:26:51
Right, any (conduit) people care to help me clean up some code?
lpaste_ 2017-02-10 02:27:48
merijn pasted "Conduit auto-sized request" at http://lpaste.net/352314
phadej 2017-02-10 02:28:01
pavonia: it's different also, when you have some state in the parser for example
phadej 2017-02-10 02:28:45
(relates to liftA2 (&&) isn't short-circuiting, but sometimes you need it to be)
biglama 2017-02-10 02:32:37
tsahyt : the running time is great !
tsahyt 2017-02-10 02:32:51
biglama: I hope the result is also correct
dramforever 2017-02-10 02:32:52
> liftA2 (&&) (Just False) (Just undefined)
lambdabot 2017-02-10 02:32:55
Just False
dramforever 2017-02-10 02:33:01
Well for some definition of short-circuiting :P
dramforever 2017-02-10 02:33:10
> liftA2 (&&) (Just False) Nothing -- of course
lambdabot 2017-02-10 02:33:13
Nothing
bollu 2017-02-10 02:33:21
does GHC generate LLVM by default?
merijn 2017-02-10 02:33:31
bollu: No, default is native code
bollu 2017-02-10 02:33:45
merijn: the LLVM is generated from STG?
tsahyt 2017-02-10 02:33:50
on the topic of LLVM, I was wondering, are there any benefits to using the LLVM backend?
dhalgren_ 2017-02-10 02:33:55
ghc panic? "thread blocked indefinitely in an MVar operation" I'm pretty sure its just a 15yro laptop running out of mem; but is it worth a bug report?
bollu 2017-02-10 02:33:55
merijn: if so, I'm super interested in the generated LLVM code
bollu 2017-02-10 02:34:17
dhalgren_: 15 years old laptop? laptops existed back then? :O
tsahyt 2017-02-10 02:34:27
bollu: they did, I remember thinkpads from the 90s even
tsahyt 2017-02-10 02:34:33
IBM thinkpads those were
merijn 2017-02-10 02:34:38
bollu: I believe both go "Haskell -> Core -> STG -> Cmm" and then the default goes "Cmm -> native code" whereas LLVM goes "Cmm -> LLVM assembly -> LLVM stuff -> native code"
dhalgren_ 2017-02-10 02:34:39
bollu: early 00s, sure
bollu 2017-02-10 02:34:48
ah, I see
mniip 2017-02-10 02:34:53
moo
bollu 2017-02-10 02:35:07
dhalgren_: I was too young to remember the early 00s. TIL you had laptops
bollu 2017-02-10 02:35:16
wel, somewhat young
merijn 2017-02-10 02:35:22
bollu: LLVM (usually) performance a decent bit better on numeric code, but the GHC native code generally does better on "non-numeric" code :)
bollu 2017-02-10 02:35:38
merijn: :) "non numberic" being "everything else"? :P
bollu 2017-02-10 02:35:45
merijn: do you know of a detailed analysis?
merijn 2017-02-10 02:35:52
bollu: Not really
bollu 2017-02-10 02:36:02
merijn: like, I wanted to help with generating better LLVM tbh
bollu 2017-02-10 02:36:05
or at least
bollu 2017-02-10 02:36:12
learn how LLVM is generated for GHC
merijn 2017-02-10 02:36:19
bollu: Pretty sure you can have it dump out the generated LLVM
merijn 2017-02-10 02:36:38
bollu: Those questions are probably going to get better answers in #ghc and on the ghc-dev mailing list
cocreature 2017-02-10 02:36:46
bollu: you can help angerman with his llvm bitcode generation plugins for ghc
merijn 2017-02-10 02:37:02
bollu: Pretty sure LLVM help is plenty welcome if you have llvm experience :)
dhalgren_ 2017-02-10 02:37:06
bollu: actually its second hand; old equipment I got for free just a couple of years ago; took it as a challenge to use regardless of its age :D but my partner had a toshiba from early 00s and used it till the screen cracked just a couple of years back
bollu 2017-02-10 02:37:40
merijn: well, I'm "new" (as in, I've messed about but I don't know much). However, I'll be spending around the next year learning a bunch about LLVM
bollu 2017-02-10 02:37:50
merijn: so I'd like to help with GHC, hopefully
bollu 2017-02-10 02:38:01
(dream since I was a teenager and all that :P)
tsahyt 2017-02-10 02:39:22
biglama: how does it compare to the C++ implementation on the 200000 line file now?
bollu 2017-02-10 02:39:23
cocreature: do I ping him?
dhalgren_ 2017-02-10 02:39:37
anyhow, I'm gonna ignore the ghc panic; its the machine surely...
cocreature 2017-02-10 02:40:32
bollu: that's probably best (or search for his email address, I'm not sure how actively he monitors irc). the repos are on github https://github.com/angerman but it probably makes sense to ask him what needs to be done
cocreature 2017-02-10 02:40:44
he was looking for help a while back so I'm sure he'll welcome any contributor
bollu 2017-02-10 02:40:55
cocreature: I'm somewhat of a noob, but I'm ready to learn. I hope he is okay with that?
cocreature 2017-02-10 02:41:09
bollu: I can't answer that question for him :)
cocreature 2017-02-10 02:41:16
bollu: but I would be very surprised if not
bollu 2017-02-10 02:41:21
cocreature: heh, thanks
biglama 2017-02-10 02:41:31
tsahyt: yes, the output is ok !
biglama 2017-02-10 02:41:39
tsahyt: I owe you a beer
tsahyt 2017-02-10 02:41:56
heh it's alright, all I did was change some imports after all
tsahyt 2017-02-10 02:42:10
and while I was at it I got a new idea on how to tackle this problem I'm working on, so it's win-win
cocreature 2017-02-10 02:42:45
bollu: another llvm related task is bundling llvm with ghc so that it stops being a second class backend. thoughtpolice has been planning that for quite some time but I don't know what the current state is
biglama 2017-02-10 02:42:55
tsahyt: so you just become lazy and everything is all right ? damn
tsahyt 2017-02-10 02:43:29
yeah, I'm not quite sure why the difference is that massive. attoparsec is written with incremental parsing in mind though, so that might have something to do with it
biglama 2017-02-10 02:43:54
this is definitively an improvement over megaparsec then
tsahyt 2017-02-10 02:44:54
dunno, maybe megaparsec would have been a lot faster with lazy text underneath as well
bollu 2017-02-10 02:45:10
cocreature: do you have anything related to LLVM in mind BTW?