Search Haskell Channel Logs

Friday, February 3, 2017

#haskell channel featuring yushyin, Tuplanolla, mniip, jle`, lambdabot, geekosaur, and 5 others.

erisco 2017-02-03 12:48:31
how might you document the length function
Lokathor 2017-02-03 12:49:02
"this returns the number of entries within this functor"
erisco 2017-02-03 12:49:15
that isn't what length does oO
Lokathor 2017-02-03 12:49:24
:t length
lambdabot 2017-02-03 12:49:26
Foldable t => t a -> Int
Lokathor 2017-02-03 12:49:31
Foldable*
erisco 2017-02-03 12:49:50
what is an entry?
Lokathor 2017-02-03 12:50:05
the 'a' part in 't a'
erisco 2017-02-03 12:50:20
so is the answer always 1?
Lokathor 2017-02-03 12:50:27
no
Lokathor 2017-02-03 12:50:39
in fact it's rarely one i suspect
erisco 2017-02-03 12:50:54
I only see one "a" :P
Lokathor 2017-02-03 12:51:08
in a [Int], it's the number of ints, in a Maybe String, it's how many strings you have, and so on
Lokathor 2017-02-03 12:51:38
it's an easy argument to makt that there's more to it than one sentence, but IRC doesn't lend itself to "more than a sentence" things
erisco 2017-02-03 12:51:43
is [1,1,2] 3 Ints or 2?
Lokathor 2017-02-03 12:51:51
it's three of them
wonder924 2017-02-03 12:51:52
where does the "nofib" benchmark suite get its name "nofib" ?
erisco 2017-02-03 12:52:18
is [undefined,undefined,undefined] 3 Ints or 2?
Lokathor 2017-02-03 12:52:28
still three :P
yushyin 2017-02-03 12:52:34
'Returns the size/length of a finite structure as an Int.' says the doc
Lokathor 2017-02-03 12:53:00
yushyin, but how *would you* write it?
erisco 2017-02-03 12:53:27
how many Ints is (1,2) ?
Lokathor 2017-02-03 12:53:37
oddly, just one
Lokathor 2017-02-03 12:53:44
because of how the Foldable is defined for (.)
Lokathor 2017-02-03 12:53:46
(,) *
mniip 2017-02-03 12:54:04
> length (1,2)
lambdabot 2017-02-03 12:54:06
1
mniip 2017-02-03 12:54:10
yup
erisco 2017-02-03 12:55:04
I am just highlighting that despite the explanation seeming clear it really doesn't tell us much
yushyin 2017-02-03 12:55:29
Lokathor: yeah, but because of your discussion I was curious what is written in the documentation :)
jle` 2017-02-03 12:55:48
maybe length can be defined as the length of the list returned by toList
erisco 2017-02-03 12:55:52
even if we just consider the old length before Foldable was put in Prelude, i.e. lists only, the explanation is not clear
Lokathor 2017-02-03 12:55:59
if i had written a whole deal about Foldable earlier in the module, as I would have naturally, I think it would explain plenty
erisco 2017-02-03 12:56:35
it leaves a lot for the reader to figure out
erisco 2017-02-03 12:56:57
when we write such comments we're really just trying to tip the reader off to these facts that are more complicated to explain
Lokathor 2017-02-03 12:57:10
of course, you'd still want to give some examples, hopefully in code blocks that the compiler can auto-test during testing (hey-o rust!) and exaplin any gotchas such as with tuple
erisco 2017-02-03 12:57:26
which is fine, but you cannot blame one for wanting to be more precise as well
Lokathor 2017-02-03 12:57:49
i suppose
Lokathor 2017-02-03 12:58:09
I'd say that the explanation required is often proportional to the difficulty of setting up a proper ability to test it out yourself
erisco 2017-02-03 12:58:09
I really don't know how to explain length precisely other than with the definition itself
Lokathor 2017-02-03 12:58:27
so with length, you don't have to say much, it's easy to test
Lokathor 2017-02-03 12:58:48
with a websocket library you want to explain more because it's pretty mysterious if things don't work what went wrong
erisco 2017-02-03 12:59:05
you might add other facts though, such as 0 <= length xs
Lokathor 2017-02-03 12:59:13
well
Lokathor 2017-02-03 12:59:24
length is mistyped in the first place I'd say
Lokathor 2017-02-03 12:59:28
it should be Word
erisco 2017-02-03 12:59:40
and length xs + length ys = length (xs ++ ys)
Lokathor 2017-02-03 12:59:45
but it's not for ergonomic reasons
Lokathor 2017-02-03 13:00:02
:t (++)
lambdabot 2017-02-03 13:00:08
[a] -> [a] -> [a]
Lokathor 2017-02-03 13:00:38
:t (<>)
lambdabot 2017-02-03 13:00:41
Monoid m => m -> m -> m
Lokathor 2017-02-03 13:00:47
ah right, here we go
jle` 2017-02-03 13:01:06
> length (("a","b") <> ("c","d"))
lambdabot 2017-02-03 13:01:08
1
jle` 2017-02-03 13:01:20
> length ("a","b") + length ("c","d")
lambdabot 2017-02-03 13:01:22
2
Lokathor 2017-02-03 13:01:54
> (("a","b") <> ("c","d"))
erisco 2017-02-03 13:01:56
well as I tried to make clear I am only talking about lists at this point
jle` 2017-02-03 13:01:57
length xs + length ys = length (toList xs ++ toList ys)
lambdabot 2017-02-03 13:01:57
("ac","bd")
geekosaur 2017-02-03 13:01:58
wonder924, iirc it replaced an older benchmark suite "fibon"
Lokathor 2017-02-03 13:02:39
erisco, "length gives you the number of items in the list", if that's not enough for you i'm not sure how to help
wonder924 2017-02-03 13:04:17
geekosaur: interesting! Any idea why "fibon" was named so ?
geekosaur 2017-02-03 13:04:43
no, I barely recall it as old lore. not much mention on ghc wiki either
erisco 2017-02-03 13:04:56
Lokathor, well as I pointed out it comes down to defining "item" and "number of"
geekosaur 2017-02-03 13:04:57
I would hguess fibonacci, but ...
erisco 2017-02-03 13:05:26
if this were something other than lists then we could be genuinely confused
erisco 2017-02-03 13:06:29
it really has nothing to do with the items or elements but rather it counts :
erisco 2017-02-03 13:07:32
"length counts the number of cons in the list"
erisco 2017-02-03 13:09:31
as for the Foldable length I think you'd have to talk in terms of toList
erisco 2017-02-03 13:10:32
granted this is just folding with the list constructors so you might break it down more
jle` 2017-02-03 13:10:47
maybe, for Foldable f => f a, toList gives the number of a's ?
jle` 2017-02-03 13:10:56
er, length
mniip 2017-02-03 13:14:06
hahaha
mniip 2017-02-03 13:14:17
someone who does toList (3, 5) is in for a great surprise
erisco 2017-02-03 13:14:43
> toList (3, 5) -- okay I'll bite
lambdabot 2017-02-03 13:14:45
error:
lambdabot 2017-02-03 13:14:45
Ambiguous occurrence 'toList'
lambdabot 2017-02-03 13:14:45
It could refer to either 'F.toList',
erisco 2017-02-03 13:14:52
shock! horror!
mniip 2017-02-03 13:15:26
> Data.Foldable.toList (3, 5)
lambdabot 2017-02-03 13:15:31
[5]
erisco 2017-02-03 13:19:24
you'll also get a surprise doing listPlease (3, 5)
mniip 2017-02-03 13:19:49
:t listPlease
lambdabot 2017-02-03 13:19:51
(t, t1) -> [Char]
mniip 2017-02-03 13:20:03
my parametricity sense is tingling
erisco 2017-02-03 13:20:16
darn, I wasn't expecting your trap disarming skill to be so high
Tuplanolla 2017-02-03 13:21:54
> Data.Foldable.toList (True, 'T')
lambdabot 2017-02-03 13:21:56
"T"
mniip 2017-02-03 13:22:04
> listPlease (1, 2)
lambdabot 2017-02-03 13:22:07
"No list for you!"
mniip 2017-02-03 13:22:10
ha
mniip 2017-02-03 13:22:30
that was a surprise because I was expecting "surprise" literally
erisco 2017-02-03 13:22:56
the joke is lame but not *that* lame :P
mniip 2017-02-03 13:25:23
erisco, I updated and improved your listPlease function :)
erisco 2017-02-03 13:25:37
> listPlease (3, 9)
lambdabot 2017-02-03 13:25:40
No list for you!
erisco 2017-02-03 13:25:46
now in IO
mniip 2017-02-03 13:25:58
er no, lambdabot doesn't do IO
erisco 2017-02-03 13:26:07
:t listPlease
lambdabot 2017-02-03 13:26:08
(a, b) -> List a b
mniip 2017-02-03 13:26:47
your trap disarming skills could use some training :p
erisco 2017-02-03 13:26:48
show instance?
erisco 2017-02-03 13:28:49
I would expect there to be a Sing Nat -> Nat conversion somewhere
erisco 2017-02-03 13:29:22
no no, I mean SNat n -> Nat conversion
erisco 2017-02-03 13:29:35
which is a Sing (n :: Nat) -> Nat conversion
erisco 2017-02-03 13:30:08
wish you could hoogle packages more easily
planetstarbucks 2017-02-03 13:34:13
#haskell-beginners
erisco 2017-02-03 13:35:30
sNatToInt
erisco 2017-02-03 13:35:44
a bit hidden because it sends to Num rather than specifically Nat
Welkin 2017-02-03 13:36:27
lol erisco
Welkin 2017-02-03 13:36:35
still going on that
erisco 2017-02-03 13:36:45
it is the new hotness
erisco 2017-02-03 13:38:17
lol, a bit strange to write f x where f = const y and actually have it matter what x is
erisco 2017-02-03 13:38:57
it projects information out of the type of x
erisco 2017-02-03 13:39:07
kinda freaky! :)
Welkin 2017-02-03 13:39:22
astral projection!