Search Haskell Channel Logs

Thursday, February 23, 2017

#haskell channel featuring old1101, shapr, lambdabot, hexagoxel, dolio, digitalmentat, and 12 others.

dolio 2017-02-23 07:45:24
@free zw :: (a -> b -> c) -> F a -> F b -> F c
lambdabot 2017-02-23 07:45:24
(forall x. h . k x = p (f x) . g) => $map_F h . zw k y = zw p ($map_F f y) . $map_F g
lyxia 2017-02-23 07:46:13
TIL @free
mbw 2017-02-23 07:46:43
@free fmap :: (a -> b) -> F a -> F b
lambdabot 2017-02-23 07:46:43
g . h = k . f => $map_F g . fmap h = fmap k . $map_F f
mbw 2017-02-23 07:47:24
Is map_F the fmap instance of F?
dolio 2017-02-23 07:47:40
Yes, it assumes F is a functor, and $map_F is its mapping operation.
mbw 2017-02-23 07:47:55
This is some cool stuff.
mbw 2017-02-23 07:49:51
Alright, thanks lyxia & dolio. I shall meditate on what I have learned.
thatguy 2017-02-23 07:55:49
I want to work with graphs, is it good practice to define a graph class and define some basic properties it should have (list of nodes, are-these-adjacent-function, ..) and define a lot of standard implementations for functions like number of nodes?
lyxia 2017-02-23 07:57:23
If you want to try out many representations that seems alright.
lyxia 2017-02-23 07:57:30
thatguy: have you looked at fgl
thatguy 2017-02-23 07:57:52
is that a graph library?
lyxia 2017-02-23 07:58:04
yup, it does more or less what you said
thatguy 2017-02-23 07:58:11
I somehow have the feeling I should start off with implementing the stuff myself to get a real feeling how to work with haskell
thatguy 2017-02-23 07:58:20
lyxia, ah ok I will have a look at it
thatguy 2017-02-23 07:58:23
thanks for the help
old1101 2017-02-23 08:05:51
hello, lists concatenations are O(n) correct? Why this single-linked list can't save a pointer to the last element? So it can be O(1)
pikajude 2017-02-23 08:06:48
if you want O(1) append you can use DList
monochrom 2017-02-23 08:07:12
Our lists are immutable. This means concatenation creates a new list, not butcher the old list.
pikajude 2017-02-23 08:07:39
or you can use Seq i think
pikajude 2017-02-23 08:07:45
which is a finger tree that retains "pointers" to both ends
monochrom 2017-02-23 08:08:09
Pointer-to-last could be useful for read-only operations such as "what is the last guy" but I wouldn't want it for concatenation.
old1101 2017-02-23 08:09:58
pikajude: I'll have a read on finger trees
old1101 2017-02-23 08:10:35
monochrom: concat creates a new list? It doesn't goes all the way (O(n) to the end and append a new item?
shapr 2017-02-23 08:10:51
finger trees are awesome
monochrom 2017-02-23 08:10:59
Creates a new list.
monochrom 2017-02-23 08:11:21
You can easily test this.
monochrom 2017-02-23 08:11:28
Define x = [1,2,3].
monochrom 2017-02-23 08:11:35
Now ask about x ++ [4,5,6].
monochrom 2017-02-23 08:11:47
Now ask about x again. Has it changed?
madknight 2017-02-23 08:12:36
are all functors in haskell are endofunctors?
Tuplanolla 2017-02-23 08:12:54
Concatenation doesn't have to touch the tail of the second list, old1101. You can't really talk about "a new list" since there's sharing involved.
monochrom 2017-02-23 08:13:24
But it is the prefix in question, Tuplanolla.
old1101 2017-02-23 08:13:29
monochrom: I can't see the differente between x ++ [1] and 1 : x both seems to be concats
pikajude 2017-02-23 08:13:41
one adds 1 to the end, the other adds it to the beginning
monochrom 2017-02-23 08:13:44
I can.
digitalmentat 2017-02-23 08:13:50
is Austin Siep in this channel? or any other GHC maintainer?
monochrom 2017-02-23 08:13:53
> [4,5,6] ++ [1]
byorgey 2017-02-23 08:13:53
madknight: instance of Functor can be thought of as endofunctors on the category of Haskell types and functions between them, yes
lambdabot 2017-02-23 08:13:56
[4,5,6,1]
old1101 2017-02-23 08:13:57
pikajude: yes, but one takes (1) and another (n)
monochrom 2017-02-23 08:14:00
> 1 : [4,5,6]
lambdabot 2017-02-23 08:14:02
[1,4,5,6]
pikajude 2017-02-23 08:14:05
old1101: sorry?
monochrom 2017-02-23 08:14:07
Not equal.
roundhouse 2017-02-23 08:14:13
Hi, I'm trying to upload the documentation generated by stack via haddock to github-pages. I use "stack path" to get the local-doc-root string to locate the docs. It works on my computer, but on travis-ci it spits out "`/home/travis/.stack/global-project/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/doc/*'" (a global doc folder). Anyone know how to do this properly?
byorgey 2017-02-23 08:14:31
madknight: modulo the fact that due to issues with laziness/strictness this is not quite a well-defined category. But close enough.
monochrom 2017-02-23 08:14:42
It is as though someone is saying, "addition is faster than multiplication!"
old1101 2017-02-23 08:14:42
"The list type is a single-linked list. As such, prepend, head and tail are all O(1). However, ++ is O(n) in the size of the left-hand list."
pikajude 2017-02-23 08:14:53
> [1] ++ [4,5,6] == 1 : [4,5,6]
lambdabot 2017-02-23 08:14:56
True
madknight 2017-02-23 08:15:01
byorgey: thx
old1101 2017-02-23 08:16:21
pikajude: the results are the same, ok. But I've read that prepend is O(1) and append is O(n)
pikajude 2017-02-23 08:16:37
@src (++)
lambdabot 2017-02-23 08:16:37
[] ++ ys = ys
lambdabot 2017-02-23 08:16:37
(x:xs) ++ ys = x : (xs ++ ys)
lambdabot 2017-02-23 08:16:38
-- OR
lambdabot 2017-02-23 08:16:38
xs ++ ys = foldr (:) ys xs
pikajude 2017-02-23 08:16:47
^ why (++) is O(n)
byorgey 2017-02-23 08:16:58
pikajude: it is O(n) in the size of the first argument.
pikajude 2017-02-23 08:17:03
right
monochrom 2017-02-23 08:17:19
[1] ++ [4,5,6] is going to be O(n = 1).
old1101 2017-02-23 08:17:35
true
old1101 2017-02-23 08:18:04
so, you always have the head pointer, why it cannot have the tail pointer?
madknight 2017-02-23 08:18:22
@src (<$>)
lambdabot 2017-02-23 08:18:23
f <$> a = fmap f a
byorgey 2017-02-23 08:18:24
digitalmentat: Austin goes by the nick thoughtpolice
digitalmentat 2017-02-23 08:18:36
byorgey, thanks :)
monochrom 2017-02-23 08:18:39
It is almost useless for immutable lists.
digitalmentat 2017-02-23 08:18:44
(I also just found #ghc, so asking in there)
pikajude 2017-02-23 08:19:00
old1101: a singly linked list is structured `Cons element1 (Cons element2 (Cons element ... Nil))`
pikajude 2017-02-23 08:19:24
how would you get ahold of a tail pointer?
byorgey 2017-02-23 08:19:50
digitalmentat: yep, #ghc is a good place to ask about GHC-specific questions. Just be patient, someone might not see your question immediately but it you will probably get a repsonse eventually
byorgey 2017-02-23 08:20:15
oh, I see you already got a response, excellent =)
monochrom 2017-02-23 08:20:55
It is also important to distinguish the C++ and Java kind of "list object" from the Haskell kind of "list (no object)".
monochrom 2017-02-23 08:21:06
(Even after ignoring mutable vs immutable)
monochrom 2017-02-23 08:21:40
In Java for example, you begin with an object of two fields, head and tail. Then head points to a chain of nodes, and tail points to the last node.
monochrom 2017-02-23 08:21:57
In Haskell we don't have that object part. We just have that chain of nodes.
monochrom 2017-02-23 08:22:29
Note that in Java again, the chain has no pointer-to-last. Only the wrapper object does.
old1101 2017-02-23 08:22:36
pikajude: you wouldn't hahah, I get it now. thanks
monochrom 2017-02-23 08:23:51
It is possible to say, in Haskell, why doesn't every node has a pointer-to-last? Especially with immutability, this extra field needs only be set once at initialization, and never needs update.
monochrom 2017-02-23 08:24:34
But now you have a 133% blow up of space footprint and pointer-to-last isn't all that useful.
old1101 2017-02-23 08:26:25
monochrom: makes a lot of sense. thank you
Tuplanolla 2017-02-23 08:27:36
Note that you can still have your mutable pointer tricks, but you have to isolate that stuff to `ST` or `IO`, old1101.
pikajude 2017-02-23 08:27:39
fun fact: [] is the pointer-to-last of *every* list
monochrom 2017-02-23 08:28:14
Naw, we don't mean that by pointer-to-last.
pikajude 2017-02-23 08:28:21
ok, fair
monochrom 2017-02-23 08:28:26
"The answer is nil" is too easy!
pikajude 2017-02-23 08:28:36
no easy answers here!
old1101 2017-02-23 08:29:04
Tuplanolla: oh, I'll see this
old1101 2017-02-23 08:29:35
thank you guys, I need to go bye :))
johnw 2017-02-23 08:34:03
I finally have a definite and legitimate need for Data.Reflection! achievement gained
dolio 2017-02-23 08:36:31
Nah, there are no legitimate uses. :P
mlev 2017-02-23 08:36:34
Can anyone help me with http://stackoverflow.com/questions/42424530/haskell-applicative-functor-instance-error-cannot-construct-the-infinite-ty
johnw 2017-02-23 08:36:47
dolio: I've been waiting years for this, don't take it away now!
pikajude 2017-02-23 08:37:17
johnw: you used it to implement a REST interface, didn't you
johnw 2017-02-23 08:37:39
no, I'm using it to feed auxiliary data to a suite of Arbitrary instances, to influence how data is generated
pikajude 2017-02-23 08:37:52
pshh
monochrom 2017-02-23 08:38:38
That is a gray area.
hexagoxel 2017-02-23 08:42:20
mlev: i think `r` has a higher-ranked type and you need to add a type signature for it.
hexagoxel 2017-02-23 08:43:43
because `g` is used twice, with different specializations
Phillemann 2017-02-23 08:44:55
Using "deriving(Generic)" together with "instance ToJSON" is very handy, but I have two structures, both having a member "url". Can I have them both without explicitly defining the ToJSON instance?