cocreature 2017-02-10 08:45:20
kubbe: so the type of iterate is "Table k v -> (b -> (k, v) -> b) -> b -> b". do you know what that function does and what its arguments are?
kubbe 2017-02-10 08:46:36
I think I do. It iterates over all values in the Table, but not what the arguments are no
cocreature 2017-02-10 08:46:54
kubbe: so the first argument should be obvious. that's just the table that it iterates over
kubbe 2017-02-10 08:47:06
yes, haha
cocreature 2017-02-10 08:47:19
kubbe: are you familiar with foldl/foldr?
monochrom 2017-02-10 08:48:17
volhovm: In general, understand what is lazy what is strict, use strict when you need strict, use lazy when you need lazy.
kubbe 2017-02-10 08:48:30
i am familiar with them, but I havnt used them so much
cocreature 2017-02-10 08:48:45
kubbe: alright, let's stick with your iterate function then
monochrom 2017-02-10 08:48:53
General questions begets tautological answers.
cocreature 2017-02-10 08:49:13
kubbe: the first argument is obvious, let's move to the third argument next. that's the initial value used before the actual iteration starts
kubbe 2017-02-10 08:50:10
the third argument is the v, right? It is the value connected to the key. In our case, this is the prioritity
cocreature 2017-02-10 08:50:33
kubbe: no the third argument is the "b"
volhovm 2017-02-10 08:50:36
monochrom: so strictness is defined by the outer layer transformer, right?
cocreature 2017-02-10 08:50:45
the first is Table k v, the second is (b -> (k, v) -> b), the third is b
cocreature 2017-02-10 08:50:49
and the function returns "b"
kubbe 2017-02-10 08:51:09
Yes, okey! Hmm, let me think of this a second..
cocreature 2017-02-10 08:51:42
kubbe: the second argument is a "step" function, it takes the current accumulated value (initially this is the third argument) and a (k, v). the (k, v) is one entry in your table.
cocreature 2017-02-10 08:51:58
kubbe: this function produces a new accumulator value
monochrom 2017-02-10 08:52:02
No, the world is not a simple boolean "lazy vs strict".
cocreature 2017-02-10 08:52:23
kubbe: iterate just keeps applying the step function to each entry in your table and passes the accumulator around
monochrom 2017-02-10 08:52:31
Ever heard of 50 shades of grey? There are even more shades of lazy or strict.
volhovm 2017-02-10 08:53:06
I obviously get it, just exepcted some theorems to exist about it.
kubbe 2017-02-10 08:53:32
alright, i get that!
volhovm 2017-02-10 08:53:45
So i could understand how `MaybeT (pure $ repeat 5) >>= \a -> liftIO (print $ take 2 a)` behave in different contexts
volhovm 2017-02-10 08:53:53
depending on what is under MaybeT
volhovm 2017-02-10 08:54:01
... without testing it in ghci
cocreature 2017-02-10 08:54:02
kubbe: maybe try implementing a function that counts the number of entries in your table using "iterate" before you try the function that produces the priority queue
monochrom 2017-02-10 08:55:06
Because you have "pure", that one only needs monad laws.
dolio 2017-02-10 08:55:14
I think you can understand that expression without testing in ghci, but it doesn't have to do with strict and lazy stuff much.
kubbe 2017-02-10 08:55:19
oh, as a exercise
monochrom 2017-02-10 08:55:20
= liftIO (print (take 2 (repeat 5)))
dolio 2017-02-10 08:56:22
I think it's actually a type error as written, though.
monochrom 2017-02-10 08:57:05
Right, actually MaybeT (pure $ repeat 5) is a type error.
monochrom 2017-02-10 08:57:22
So you don't even need monad laws. You just need type judgments.
kubbe 2017-02-10 08:59:25
cocreature, well I could try. But in actual code: how should my basecase look like? I have no idea what the first input is since it doesnt work with empty, Table.empty or []
cocreature 2017-02-10 09:00:35
kubbe: you don't need a basecase, "iterate" already does the recursion for you
dolio 2017-02-10 09:00:45
If you fix it in the obvious way, though, it's what monochrom said.
monochrom 2017-02-10 09:01:42
One of the parameters of iterate is your base case. (Another one is your induction step.)
kubbe 2017-02-10 09:04:10
cocreature: http://lpaste.net/352333 this is what I have come up with so far
Boomerang 2017-02-10 09:04:52
kubbe: you don't need characterCounts in this function, you are already given a Table as input
cocreature 2017-02-10 09:04:58
kubbe: you need to pass the argument of huffmanTree' to Table.iterate, not some random "characterCounts" variable that you got from somewhere
cocreature 2017-02-10 09:05:05
also I don't know what s is supposed to be
Boomerang 2017-02-10 09:05:58
kubbe: characterCounts will be used later on along with huffmanTree to create "compress"
kubbe 2017-02-10 09:07:07
Oh, ofcourse! Okey :D
kubbe 2017-02-10 09:07:29
so: huffmanTree' = Table.iterate huffmanTree'
kubbe 2017-02-10 09:07:34
and some more stuff afterwards ofc
cocreature 2017-02-10 09:07:43
no!
kubbe 2017-02-10 09:07:44
ohh, okey Boomerang
cocreature 2017-02-10 09:07:57
now you are passing the function that you are defining using Table.iterate to Table.iterate
cocreature 2017-02-10 09:08:01
that is not going to go well
kubbe 2017-02-10 09:09:44
i have a trouble of understanding what "argument of huffmantree'" means. Either it means: Char and Int
kubbe 2017-02-10 09:09:48
or PriorityQueue
kubbe 2017-02-10 09:09:57
if you ask me :p
cocreature 2017-02-10 09:10:18
kubbe: I really recommend that you do the simpler exercise that I proposed first if you are having trouble with this
kubbe 2017-02-10 09:11:47
is it possible for you to give me an working example of Table.iterate? In code, so I can see what input it takes
kubbe 2017-02-10 09:11:55
after that i'll give that simpler exercise a go
Boomerang 2017-02-10 09:13:05
kubbe: for the simpler exercise cocreature gave you (length :: Table Char Int -> Int) if it helps the type of Table.iterate to use is Table Char Int -> (Int -> (Char, Int) -> Int) -> Int -> Int
Boomerang 2017-02-10 09:13:54
For this particula exercise, the values (Char, Int) don't matter since you're just trying to find the length
kubbe 2017-02-10 09:14:30
Yes! I want to find the length of the Table
cocreature 2017-02-10 09:16:18
kubbe: if it helps, write the function using "foldl" on lists first. iterate is just a wrapper around foldl so you can easily translate your foldl code to iterate later
kgadek 2017-02-10 09:17:47
hi. anyone knows any real-world usage of freer? I'm curious about the actual experience
kubbe 2017-02-10 09:19:25
Im going to try cocreature!
max3 2017-02-10 09:26:29
can anyone help me with this error? it doesn't seem like it should be occurring http://pastebin.com/G8fAaj1s
cocreature 2017-02-10 09:27:28
max3: where is PGArrayType from?
kubbe 2017-02-10 09:27:37
I give up
max3 2017-02-10 09:27:49
cocreature, https://github.com/databrary/databrary/blob/master/Databrary/Model/Segment.hs
max3 2017-02-10 09:28:07
cocreature, line 26 and 43
kubbe 2017-02-10 09:28:12
I have no clue what so ever to make a foldl-function work, and less how to make the algorithm work!
cocreature 2017-02-10 09:28:33
max3: which package does that module belong to?
max3 2017-02-10 09:29:20
cocreature, i think the answer to your question is the parent one as indicated by that github link
cocreature 2017-02-10 09:29:40
max3: there is no postgres folder in https://github.com/databrary/databrary/tree/master/Databrary
max3 2017-02-10 09:30:15
which module do you mean? Segment or Database.PostgreSQL.Typed.Array
cocreature 2017-02-10 09:30:15
alright it's from postgresql-typed
max3 2017-02-10 09:30:25
sorry yes
max3 2017-02-10 09:30:35
cocreature, what i don't understand
max3 2017-02-10 09:30:45
is i thought i had the syntax understood
max3 2017-02-10 09:31:01
instance PGType "segment[]" declares "segment[]" an instance of PGType
cocreature 2017-02-10 09:31:24
max3: "sement[]" is not a type (without advanced extensions)
max3 2017-02-10 09:31:44
DataKinds at the top of the file
cocreature 2017-02-10 09:31:48
ah ok
cocreature 2017-02-10 09:32:11
max3: well for PGArrayType the problem is simple, you are passing two types but PGArrayType is not a multiparam typeclass
cocreature 2017-02-10 09:32:16
haven't looked at range type yet
cocreature 2017-02-10 09:32:42
PGRangeType is also not a multiparam typeclass
Boomerang 2017-02-10 09:33:18
kubbe: don't give up! folds are just a way to simplify a certain type of recursion. Take a look at the source code for the length of a list:
Boomerang 2017-02-10 09:33:22
@src length
lambdabot 2017-02-10 09:33:22
Source not found. Maybe you made a typo?
Boomerang 2017-02-10 09:33:38
Oh, what about sum?
Boomerang 2017-02-10 09:33:45
@src sum
lambdabot 2017-02-10 09:33:45
sum = foldl (+) 0
merijn 2017-02-10 09:33:54
sum is actually a pretty terrible example, since it leaks space all over the place...
max3 2017-02-10 09:34:28
cocreature, is there any chance it could be something else? this code is running in production
Boomerang 2017-02-10 09:34:40
right, we were trying to explain how folds work, it seemed like a simple example
kubbe 2017-02-10 09:34:56
yeah, but if wanted to use that one in an actual example
cocreature 2017-02-10 09:35:00
max3: not really. maybe you are using an older version of postgresql-typed that uses a multipparamtypeclass here?
merijn 2017-02-10 09:35:06
hmmm, there really isn't a reasonable way to do a closable channel without STM, is there?
kubbe 2017-02-10 09:36:09
since I cant just learn by theory, i need to acutally see some working code and there is relative hard to actually find that in this particular language
kubbe 2017-02-10 09:36:38
I need to go brb for 15-20 minutes now, though
Tuplanolla 2017-02-10 09:36:52
Hackage is full of working code, kubbe.
Tuplanolla 2017-02-10 09:37:30
You can `cabal get` packages and look inside.
max3 2017-02-10 09:40:45
cocreature, `class (PGType ta, PGType t) => PGArrayType ta t | ta -> t, t -> ta where` from 0.4.3
max3 2017-02-10 09:40:51
that means multiparameter right?
max3 2017-02-10 09:41:04
although i don't understand the | in the definition
cocreature 2017-02-10 09:41:41
max3: yep that's multiparameter, looks like it changed in 0.5
max3 2017-02-10 09:41:52
what does the alternation mean?
cocreature 2017-02-10 09:41:56
max3: | followed by the part after this is a functional dependency
cocreature 2017-02-10 09:42:04
ta -> t means that ta uniquely determines t