Search Haskell Channel Logs

Friday, February 10, 2017

#haskell channel featuring Tuplanolla, Welkin, lambdabot, binary, barrucadu, monochrom,

binary 2017-02-10 14:01:35
I have a question about Data.Binary.decodeFileOrFail.
binary 2017-02-10 14:01:40
The code is here https://hackage.haskell.org/package/binary-0.8.4.1/docs/src/Data.Binary.html#decodeFileOrFail
binary 2017-02-10 14:01:55
This seems like the fastest way to go from a file to a Haskell data structure
binary 2017-02-10 14:02:03
My question is about the use of B.length
binary 2017-02-10 14:02:12
Specifically here: https://github.com/kolmodin/binary/blob/master/src/Data/Binary.hs#L226-L228
binary 2017-02-10 14:02:28
Why would they use B.length over B.null?
binary 2017-02-10 14:02:47
B.null is O(1) whereas B.length is O(n)
monochrom 2017-02-10 14:02:52
I don't know. I bet personal mood.
monochrom 2017-02-10 14:03:03
What is B?
Welkin 2017-02-10 14:03:14
but is it actually evaulated that way?
binary 2017-02-10 14:03:21
import qualified Data.ByteString as B ( hGet, length )
Welkin 2017-02-10 14:03:21
the result is either 0 or anything else
Welkin 2017-02-10 14:03:28
it's possible it is still O(1)
monochrom 2017-02-10 14:03:35
OK, now how do you know that B.length is O(n)?
binary 2017-02-10 14:03:48
Docs. One sec!
binary 2017-02-10 14:04:16
https://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString-Lazy.html#v:null
monochrom 2017-02-10 14:04:50
Computer, is "Data.ByteString" the same as "Data.ByteString.Lazy"?
binary 2017-02-10 14:04:55
The only theory I have on why they'd use length is laziness
monochrom 2017-02-10 14:05:02
> "Data.ByteString" == "Data.ByteString.Lazy"
lambdabot 2017-02-10 14:05:06
False
Welkin 2017-02-10 14:05:15
binary: non-strictness, you mean
binary 2017-02-10 14:05:25
Also, Welkin, I believe that `case` will force evaluation for the pattern match
monochrom 2017-02-10 14:05:27
OK, so why is the doc of Data.ByteString.Lazy relevant?
binary 2017-02-10 14:05:39
Oops!
binary 2017-02-10 14:05:57
Ahh, both are O(1) in strict!
binary 2017-02-10 14:05:58
https://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString.html#v:null
binary 2017-02-10 14:06:34
Probably using an if is still a bit faster (saves a comparison) but not a huge deal
monochrom 2017-02-10 14:06:40
I was asking about B.length.
monochrom 2017-02-10 14:07:12
OK, you now know.
monochrom 2017-02-10 14:07:31
So it's just swing of mood when the author wrote it. There is insignificant difference.
binary 2017-02-10 14:07:50
Cool, thanks!
monochrom 2017-02-10 14:07:53
With that tiny difference, do not over-analyze it.
binary 2017-02-10 14:08:05
Nah, it's just that I found the wrong docs
Welkin 2017-02-10 14:08:32
but, but, they used end-of-line commas instead of beginning-of-line commas!
barrucadu 2017-02-10 14:09:23
The commas-at-the-start-of-the-line thing is such a weird convention I've never seen in any other language
Welkin 2017-02-10 14:09:33
yeah
Welkin 2017-02-10 14:09:36
I love it o.o
barrucadu 2017-02-10 14:09:45
It's great
Welkin 2017-02-10 14:09:54
tried it in javascript
Clint 2017-02-10 14:09:54
amen
Welkin 2017-02-10 14:09:55
got errors
monochrom 2017-02-10 14:10:24
There was a time commas or semicolons at the beginning helped indentation algorithms.
Welkin 2017-02-10 14:10:33
oh lol
monochrom 2017-02-10 14:10:46
I still have old code doing it in do-blocks
Welkin 2017-02-10 14:10:48
you reminded me of some webpage that shows C in different styles
Welkin 2017-02-10 14:10:50
haha
Welkin 2017-02-10 14:10:53
I wonder if I can find it
Welkin 2017-02-10 14:11:00
it shows "lisp style"
Welkin 2017-02-10 14:11:05
and "python style"
monochrom 2017-02-10 14:11:28
Like this? http://lpaste.net/311978
Welkin 2017-02-10 14:11:47
something like that, yeah
monochrom 2017-02-10 14:11:49
There was a tweet inspiring mine
geekosaur 2017-02-10 14:12:31
there was a webpage showing a course example of java in python style like that
Welkin 2017-02-10 14:12:48
geekosaur: maybe that was it?
geekosaur 2017-02-10 14:12:50
(with the page begging people to do something about the prof/ta...)
monochrom 2017-02-10 14:13:01
haha that's worse. a whole course with a teacher doing that for a dozen weeks.
barrucadu 2017-02-10 14:13:34
I remember a page with C written in increasingly-bizarre styles, and I'm sure it included "Peyton-Jones Style" which had leading semicolons.
monochrom 2017-02-10 14:14:07
I am symphathetic to that style but you really need a computer to auto-insert the {;}s because with this format you can't trust a human to do it right.
Welkin 2017-02-10 14:14:10
LOL
Welkin 2017-02-10 14:14:13
yes barrucadu
Welkin 2017-02-10 14:14:15
that was it
Welkin 2017-02-10 14:14:17
I remember that too
barrucadu 2017-02-10 14:14:21
Ah, this: https://twitter.com/aisamanra/status/779057953542242304
geekosaur 2017-02-10 14:14:25
which, apparently, was in turn a misattribution of https://www.reddit.com/r/ProgrammerHumor/comments/2wrxyt/a_python_programmer_attempting_java/
monochrom 2017-02-10 14:15:36
w00t I love the one using multiple semicolon stuffers
monochrom 2017-02-10 14:16:06
The battle between space and tab has finally ended!
Tuplanolla 2017-02-10 14:16:34
How do you open the Twitter link? It's tag soup for me.
monochrom 2017-02-10 14:18:04
hahaha I accidentally found a tweet making a joke about intuitionistic logic.
monochrom 2017-02-10 14:18:25
https://twitter.com/aisamanra/status/807718428886716417
monochrom 2017-02-10 14:19:02
This tweeter is funny
monochrom 2017-02-10 14:34:53
Haha so the redditor's username is "mkdir"