Search Haskell Channel Logs

Tuesday, February 7, 2017

#haskell channel featuring noan, lambdabot, hpc, opqdonut, reactormonk, Profpatsch,

opqdonut 2017-02-07 00:45:43
reactormonk: well with --dry-run you only get the output, without modifications to your .cabal file
reactormonk 2017-02-07 00:46:13
opqdonut, thanks
merijn 2017-02-07 00:49:12
dfeuer: You're working on containers, right?
Profpatsch 2017-02-07 01:24:51
Is the strictContents fh = T.getContents fh >>= \s -> seq (T.length s) s
Profpatsch 2017-02-07 01:24:54
tick
Profpatsch 2017-02-07 01:25:13
*trick the way to go?
merijn 2017-02-07 01:25:37
Profpatsch: eh, getContents for strict Text is already strict
merijn 2017-02-07 01:25:44
Profpatsch: So..."no"? :)
Profpatsch 2017-02-07 01:26:08
merijn: Hm, for non-strict stuff like String?
merijn 2017-02-07 01:26:32
Profpatsch: getContents in base is lazy, the ones from Text/ByteString are only lazy IO for the lazy versions
Profpatsch 2017-02-07 01:26:37
merijn: That means if my code reaches T.getContents it will always read the handle at that second?
merijn 2017-02-07 01:26:58
Profpatsch: Assuming T is a qualified import of strict Text, yes
Profpatsch 2017-02-07 01:27:17
Because I had the problem that the handle was closed once the server tried to read the actual values from the handle.
Profpatsch 2017-02-07 01:27:27
(on page refresh in my case)
merijn 2017-02-07 01:28:55
Profpatsch: That shouldn't happen with the strict versions
merijn 2017-02-07 01:29:14
Profpatsch: Did you (perhaps) accidentally close the handle elsewhere/leak the handle from a bracket?
BernhardPosselt 2017-02-07 01:29:16
how would i partially apply reverse (map (map toUpper) ["hi", "ho"])
BernhardPosselt 2017-02-07 01:29:23
so that the list can be passed in
merijn 2017-02-07 01:29:58
:t reverse . map (map toUpper)
lambdabot 2017-02-07 01:30:00
[[Char]] -> [[Char]]
Profpatsch 2017-02-07 01:30:07
merijn: I wrapped withBinaryFile, like so: http://lpaste.net/352165
BernhardPosselt 2017-02-07 01:30:07
ty
Profpatsch 2017-02-07 01:30:13
Maybe that caused the problem.
merijn 2017-02-07 01:32:14
Where's withBinaryFile from?
Profpatsch 2017-02-07 01:32:18
But I can't see how that could happen, really.
Profpatsch 2017-02-07 01:32:26
system.IO
Profpatsch 2017-02-07 01:33:32
The handle stuff should be wrapped in readBinaryFile me thinks.
merijn 2017-02-07 01:33:43
hmmm, that's odd, I don't suppose you have minimal example
Profpatsch 2017-02-07 01:34:24
OH
Profpatsch 2017-02-07 01:34:31
s <- BL.hGetContents h
Profpatsch 2017-02-07 01:34:33
BL.length s `seq` pure s
Profpatsch 2017-02-07 01:34:35
y
merijn 2017-02-07 01:34:50
Lazy bytestring, looks like?
Profpatsch 2017-02-07 01:34:53
Like you said, BL.hGetContents is lazy indeed.
merijn 2017-02-07 01:34:58
Yeah, that's the issue
Profpatsch 2017-02-07 01:35:42
So my function is http://lpaste.net/352166
merijn 2017-02-07 01:36:29
simply replacing that with strict bytestring should avoid the 'seq' + length bit
merijn 2017-02-07 01:36:42
Also, this hack attempt at forcing it is subtly broken :p
Profpatsch 2017-02-07 01:36:52
how?
merijn 2017-02-07 01:38:09
'seq x y' causes 'x' to be forced when 'seq x y' is forced, but nothing in that code actually forces 'seq x y'
Profpatsch 2017-02-07 01:38:23
Ah, I missed the aeson eitherDecodeStrict' function.
Profpatsch 2017-02-07 01:38:53
merijn: Hm, it at least didn't throw a closed handle error once I inserted that.
Profpatsch 2017-02-07 01:40:11
merijn: Does the same apply to B/BL.hPut?
Profpatsch 2017-02-07 01:40:25
Will hPut defer if the bytestring is lazy?
hpc 2017-02-07 01:41:06
the "lazy" in "lazy bytestring" is the same as the lazy in []
Profpatsch 2017-02-07 01:41:32
aeson only exports an encode function to lazy BS
hpc 2017-02-07 01:41:33
it just means the bytestring is an ordinary list of strict bytestring "chunks"
hpc 2017-02-07 01:41:46
following non-strict semantics for evaluation
hpc 2017-02-07 01:41:58
lazy IO is on a different axis
Profpatsch 2017-02-07 01:41:59
So if I say BL.hPut $ decode …, will it defer the actual writing?
hpc 2017-02-07 01:42:03
no
hpc 2017-02-07 01:42:12
read the documentation for hPut, it will say if it does lazy IO
hpc 2017-02-07 01:42:22
very few things do, and they are all very explicit about doing so in their haddock
Profpatsch 2017-02-07 01:43:03
Ah, the hPut function is the same for all variants of ByteString.
Profpatsch 2017-02-07 01:43:14
hpc: merijn Thanks for the help.
Profpatsch 2017-02-07 01:43:22
That's enlightening.
merijn 2017-02-07 01:43:58
People drastically overestimate the amount of lazy IO in base
noan 2017-02-07 01:44:49
(Foo Bar) is a tuple of 2 right?
noan 2017-02-07 01:44:53
that's haskell notation for it?