Search Haskell Channel Logs

Sunday, February 5, 2017

#haskell channel featuring cocomo, simendsjo, tfc, michaelt, dramforever, lambdabot,

cocomo 2017-02-05 01:57:36
hi, how do you destruct a list in function definition fn (x:xs) = ... is this the right syntax?
dramforever 2017-02-05 01:59:05
yes
michaelt 2017-02-05 01:59:48
cocomo: but don't forget the other case!
sternmull 2017-02-05 02:00:17
in which package is floldr' and floldl'? The Prelude seems to only provide the non-strict versions.
cocomo 2017-02-05 02:00:23
thank you very much.
michaelt 2017-02-05 02:00:38
sternmull: foldl' is in Data.List is that what you mean?
michaelt 2017-02-05 02:00:54
it should be in the Prelude I would think
sternmull 2017-02-05 02:01:54
michaelt: Yes think that is what i was looking for. Thanks.
michaelt 2017-02-05 02:02:14
sternmull: it is the left fold, foldl' where strictness is especially an issue.
sternmull 2017-02-05 02:03:31
michaelt: I am reading about strictness and wanted to play with the different folds. But the tick-versions are not defined and i saw no information where they should come from.
michaelt 2017-02-05 02:07:49
sternmull: I remember learning a lot about foldr foldl foldl' from say pp 7-40 of this http://www.slideshare.net/tibbe/highperformance-haskell The author is maybe a little hard on strictness and it's now pretty old, but it has lots of nice information
michaelt 2017-02-05 02:08:06
hard on /laziness/ rather
cocomo 2017-02-05 02:10:07
using fn name (x:xs) = ... for destructuring List a core feature or does it requires importing a package?
michaelt 2017-02-05 02:10:36
it's hard to think of a more core feature than that
cocomo 2017-02-05 02:11:15
I am using a flavor of haskel where it is complaining that (:) unknown operator.
michaelt 2017-02-05 02:12:22
oh what version
michaelt 2017-02-05 02:12:25
> let fn name [] = []; fn name (x:xs) = (name,x) : fn name xs in fn "hi" ["Meredith", "Steve"]
lambdabot 2017-02-05 02:12:27
[("hi","Meredith"),("hi","Steve")]
cocomo 2017-02-05 02:13:11
is it allowed to ask about purescript here? its a flavor of haskel
michaelt 2017-02-05 02:13:56
oh purescript doesn't use : [] etc
michaelt 2017-02-05 02:14:02
I think there's a #purescript
cocomo 2017-02-05 02:15:17
michaelt: thank you. they don't have many users. its very quite there
sternmull 2017-02-05 02:16:36
hm, ghci uses around 90MB when i call "print (foldl' (+) 0 [1..1000000])". Isn't that supposed to avoid such allocations?
tfc 2017-02-05 02:22:41
sternmull: how did you measure that it's using 90mb? i have no answer to your question, but i am curious
sternmull 2017-02-05 02:23:27
tfc: By using ":set +s" ghci tells me duration and memory usage after each call.
tfc 2017-02-05 02:24:08
oh that is useful. thank you
hpc 2017-02-05 02:24:20
that number isn't the maximum resident memory, it's the total number of allocations
hpc 2017-02-05 02:24:30
optimizations will probably make it mutate in place
hpc 2017-02-05 02:24:46
but the benefit of foldl' over foldr in that particular case is that you simply don't overflow
simendsjo 2017-02-05 02:25:22
I tried asking the following in #haskell-beginners some time ago, but I'll try reposting here as I didn't get any answers: I'm having some big issues trying to understand ((sequence .) . fmap). I think its the combination of composition, type-classes, higher-order functions and parametric polymorphisms that is causing a lot of confusion. I'd be happy if someone could look at my "understanding" of this and point out my mistakes:
simendsjo 2017-02-05 02:25:22
https://gist.github.com/simendsjo/ddcfd2dc88c98cf273bacebcbee1c1ce
simendsjo 2017-02-05 02:25:22
hpc 2017-02-05 02:25:31
most of the time, ghc's memory allocations consist of incrementing a register, so it's not something you should try to optimize first
sternmull 2017-02-05 02:26:41
hpc: How does incrementing a register does cause an allocation?
sternmull 2017-02-05 02:26:57
maybe i have a different concept of a register...
dramforever 2017-02-05 02:27:09
sternmull: No that's not what it means
dramforever 2017-02-05 02:28:00
GHCi goes, generate a list node, allocate that, generate 1, allocate that, generate another list node, allocate that, generate 2, allocate that, generate 1 + 2, allocate that
dramforever 2017-02-05 02:28:45
But at the same time GC sees, oh hey list node not needed anymore, deallocate that, number not needed, deallocate that, etc.
tfc 2017-02-05 02:29:26
how to uncover then with ghci measures that one optimized variant is better than the other?
sternmull 2017-02-05 02:29:27
so it is simply that ghci does not optimize the allocation of the temporaries away, right?
dramforever 2017-02-05 02:29:42
yes
dramforever 2017-02-05 02:29:48
GHCi does not support optimizations
hpc 2017-02-05 02:30:13
it will load compiled code if it exists though
hpc 2017-02-05 02:30:22
and that can be compiled with optimizations
sternmull 2017-02-05 02:30:33
that is sad, playing interactively to test performance of different notations had been nice. But good to know that i should not give too much attention to resource usage in ghci.
dramforever 2017-02-05 02:31:53
sternmull: Uh, you do get that the 'bytes' part is *not* memory usage in the conventional sense, right?
tfc 2017-02-05 02:31:54
is there some nice framework which can be used for compiling little benchmarks which tells what ghci will not tell due to lack of optimization?
michaelt 2017-02-05 02:31:58
sternmull: yes the results of ghci :set +s are of limited use
dramforever 2017-02-05 02:32:53
[criterion] provides a powerful but simple way to measure software performance
hpc 2017-02-05 02:32:54
for a more sophisticated set of numbers, look at ghc's profiling features
dramforever 2017-02-05 02:32:56
http://hackage.haskell.org/package/criterion
Xnuk 2017-02-05 02:33:14
simendsjo: You might make a mistake in Line 32: `(g .) f` is `a -> c`, while `(g .) . f` is not.
dramforever 2017-02-05 02:33:15
for benchmarking try this criterion thing
michaelt 2017-02-05 02:33:28
for time, criterion, other things ghc profiling options
simendsjo 2017-02-05 02:35:45
Xnuk: Thanks! I'll go through everything again.
dramforever 2017-02-05 02:35:59
Is there a way to 'see' how my cabal package description will render before publishing to hackage?
hpc 2017-02-05 02:36:26
you can preview an upload on hackage
hpc 2017-02-05 02:37:23
and i think now you can upload non-release versions too, which stick around and you can mark as release after the fact?
dramforever 2017-02-05 02:37:27
Oh right, that
michaelt 2017-02-05 02:40:17
tfc here's a dumb use of criterion http://sprunge.us/hTdD
michaelt 2017-02-05 02:40:42
tfc: together with the results of running it , compiling with -)2
michaelt 2017-02-05 02:40:57
tfc: I mean ghc -O2
tfc 2017-02-05 02:41:17
what makes it dumb?
michaelt 2017-02-05 02:41:32
tfc I just mean simple
tfc 2017-02-05 02:41:38
oh, ok :)
michaelt 2017-02-05 02:41:38
tfc: sorry that wasn't clear
michaelt 2017-02-05 02:42:17
tfc `whnf` takes a function and an argument and the idea is to measure how long it takes to get to weak head normal form
tfc 2017-02-05 02:43:10
ok, i read some stuff about whnf, but i'm not sure if i really understand all implications of that
michaelt 2017-02-05 02:43:14
with Int this wouldnt differ from using `nf` which measures how long it takes to get the whole result worked out.
michaelt 2017-02-05 02:43:45
for Int they come to the same, for [Int], where in whnf if we have either [] or 12:_ never mind what _ is
sternmull 2017-02-05 02:43:46
Now I compile "main = print $ foldl' (+) 0 [1..10000000]" with "ghc -O2 -prof foo.hs" and run it with "./foo +RTS -p" and have 320MB of allocations in the profile output. This number scales with the length of the list. I expected the allocations to get optimized away...