zipper 2017-01-26 20:59:34
Hello, so I have a question regarding resource usage and the various "string" types. In say Network.Wreq when I get from a URL and get a lazy bytestring what exactly does that mean?
zipper 2017-01-26 20:59:54
OK I have bytes yes but they're not being processed on how?
zipper 2017-01-26 21:00:21
Is there a way I could just make a request and get *only* the response header in memory
zipper 2017-01-26 21:01:14
Because the Lazy ByteString is still in memory as far as I can understand, what would happen if I converted it to a String? Would it somehow use way more memory?
zipper 2017-01-26 21:02:07
"A key feature of lazy ByteStrings is the means to manipulate large or unbounded streams of data without requiring the entire sequence to be resident in memory."
zipper 2017-01-26 21:02:19
but since I read it over the network it is in memory, right?
zipper 2017-01-26 21:02:31
Since it's not like I'm reading from disk
zipper 2017-01-26 21:02:42
or does memory here means the stack?
qcrvszvz 2017-01-26 21:03:44
Lazy IO might enable you to already start processing the initial part of the returned bytestring before the rest is even transmitted over the wire
zipper 2017-01-26 21:04:06
qcrvszvz: Oh nice this is what I want
shayan_ 2017-01-26 21:04:09
Any of you have experience practicing Haskell on codewars?
zipper 2017-01-26 21:04:16
but I only want the first few bytes
zipper 2017-01-26 21:04:22
Since I want the content type
zipper 2017-01-26 21:04:41
and if I get it is a certain type I then read the
zipper 2017-01-26 21:04:48
the rest I don't care about
zipper 2017-01-26 21:05:22
:t Data.ByteString.Lazy.take
lambdabot 2017-01-26 21:05:24
Int64 -> BSLC.ByteString -> BSLC.ByteString
zipper 2017-01-26 21:05:27
that looks great ^
zipper 2017-01-26 21:05:52
Is there a chance the head would be greater than 64 bytes, so hard to know
qcrvszvz 2017-01-26 21:05:54
a) Lazy ByteStrings are chunked, i.e.: there is some minimum amount of data you always read to even start constructing your bytestring (which might be large, say 4096 bytes)
zipper 2017-01-26 21:06:31
qcrvszvz: I'm ok with that
qcrvszvz 2017-01-26 21:06:48
b) Check if your network library actually does lazy io and isn't lying to you about the bytestring really being lazy
zipper 2017-01-26 21:07:30
qcrvszvz: I returns a lazy bytestring so it does
zipper 2017-01-26 21:07:41
*it
zipper 2017-01-26 21:07:50
My issue is that I have a small VM on Digital Ocean that always runs out of memory because it sometimes tries to download videos
qcrvszvz 2017-01-26 21:08:08
but if it doesn't the idiomatic way is to just start parsing and don't look at the part you don't need; _usually_ what you don't look at doesn't get read
zipper 2017-01-26 21:08:18
qcrvszvz: Thanks I think I get what you mean
zipper 2017-01-26 21:08:27
Gonna come back if something breaks
osa1 2017-01-26 21:14:26
does anyone know a package like this on stackage lts 7.14: https://hackage.haskell.org/package/privileged-concurrency ? I need read-only MVars, Chans etc.
Bish 2017-01-26 21:38:15
can you guys bring the charm of functional programming closer to me? i've never (really) tried to code haskell, since starting is giving me a hard time. what's the point of having a language with functions without sideeffects, if you THEN define that some functions have
Ferdirand 2017-01-26 21:39:04
you don't really define that some have
Bish 2017-01-26 21:39:20
that's the point i am not getting
Bish 2017-01-26 21:41:02
i feel like the biggest benefit in this kind of programming is that you're really hard forced to have good structured data, and the same could be achieved with discipline
bshelden 2017-01-26 21:41:30
Certainly, but would you rather spend those mental cycles being disciplined or working on the solution?
liste 2017-01-26 21:41:58
Bish: you can do "math" with functions without side-effects, eg. if you have "f = a b c" and "g = a f", then g can be simplified to "g = a (a b c)"
Bish 2017-01-26 21:42:00
no, but none ever talks about this fact, that is what i feel like
Ferdirand 2017-01-26 21:42:10
discipline does not work in practice, we see countless examples every day
liste 2017-01-26 21:42:24
Bish: and so on, to reason with your code easily without running it
Ferdirand 2017-01-26 21:42:32
anyway, values in IO are not functions, they are "actions" if you like
Ferdirand 2017-01-26 21:42:41
things with side effects
Ferdirand 2017-01-26 21:42:45
and you cannot call them from haskell
liste 2017-01-26 21:43:01
Bish: and note that very few functions have side-effects, mostly debugging functions (Debug.trace) and functions that are misused (unsafePerformIO)
Bish 2017-01-26 21:43:07
so they're evaluated alongside with haskell rather than in the function?
Ferdirand 2017-01-26 21:43:23
what you do with actions is that you combine them to form a program
liste 2017-01-26 21:43:36
Bish: IO actions don't have side-effects, they *are* effects. (not "side")
Ferdirand 2017-01-26 21:43:47
they are not actually run when you combine them
Ferdirand 2017-01-26 21:44:14
but eventually, you build a single action, that you call main, and that gets executed by the runtime
Bish 2017-01-26 21:44:27
i am confused, still, maybe i just need to write something, i learned a lot of languages but starting haskell is one different thing enitrely
Bish 2017-01-26 21:44:42
Ferdirand: thanks that helps