lyxia 2017-02-25 05:49:06
codedmart: what's App
lyxia 2017-02-25 05:49:12
no pun intended
bollu 2017-02-25 05:49:23
Aku hey
bollu 2017-02-25 05:49:30
oh
bollu 2017-02-25 05:49:32
he's not around
codedmart 2017-02-25 05:49:43
lyxia: `ReaderT AppConfig (ExceptT ServantErr (LogM IO)) a` this is App in my stack.
lyxia 2017-02-25 05:50:12
codedmart: And you want StateT s App ?
Athas 2017-02-25 05:50:20
I'm getting a segfault from a program compiled with GHC 8.0.2. Any advice on how to go about debugging this?
lyxia 2017-02-25 05:50:36
codedmart: this just uses StateT's lift.
lyxia 2017-02-25 05:53:12
Athas: you could wrap your unsafe operations with "trace" to get an idea of where you get stuck
codedmart 2017-02-25 05:54:58
lyxia: Hmm... I tried that but I get this error `Couldn't match type 't0 App' with 'StateApp'`
Athas 2017-02-25 05:55:30
lyxia: I don't have any unsafe operations, but maybe my dependencies have. Oh well.
lyxia 2017-02-25 05:55:44
Athas: ouch...
lyxia 2017-02-25 05:56:35
codedmart: did you mean to wrap it in newtype? then you would need to write/derive that instance
codedmart 2017-02-25 05:56:50
Ah
lyxia 2017-02-25 05:56:52
codedmart: but it would be simpler to just use a type synonym
codedmart 2017-02-25 05:56:52
right
ph88^ 2017-02-25 05:58:18
codedmart, you need the ReaderT and StateT for different contexts ?
codedmart 2017-02-25 06:00:22
ph88^: Mostly trying something. This is one specific section that I need some state (possibly).
ph88^ 2017-02-25 06:01:07
what are you using for the frontend these days ?
codedmart 2017-02-25 06:04:24
Maybe I am going about this all wrong though.
codedmart 2017-02-25 06:05:04
I am working on my own setup to write records to csv.
codedmart 2017-02-25 06:08:14
Where I am hitting a problem is say a `User's` addresses. They can request say `("Address Street One", "addresses.streetOne"), but I need to be able to find how many addresses there are and change this `("Address Street One", "addresses.streetOne")` to `[("Address 1 Street One", "addresses.1.streetOne"), ("Address 2 Street One", "addresses.2.streetOne"),
codedmart 2017-02-25 06:08:14
...]`. I write to file in batches so memory usage stays down.
codedmart 2017-02-25 06:10:17
My initial idea was I would track in state whether or not I was in the firstBatch and handle the header after I have the firstBatch but before I write then just handle the remaining batches. But maybe I am complicating things and going about this wrong.
Aku 2017-02-25 06:15:14
bollu: up there?
bollu 2017-02-25 06:15:26
yes
bollu 2017-02-25 06:15:28
OK, cool
bollu 2017-02-25 06:15:32
so, we were at one or more, right?
bollu 2017-02-25 06:15:40
one or more = one `then` zero or more?
bollu 2017-02-25 06:15:42
do you see that?
Aku 2017-02-25 06:15:43
ya
bollu 2017-02-25 06:15:46
OK
bollu 2017-02-25 06:15:47
so now
bollu 2017-02-25 06:15:51
we know how to write this :)
Aku 2017-02-25 06:15:51
ya
bollu 2017-02-25 06:15:58
can you paste your code again please?
Aku 2017-02-25 06:16:03
yes
lpaste_ 2017-02-25 06:16:54
Aku revised "pOneOrMore": "pOneOrMore" at http://lpaste.net/5688715794511298560
Someguy123 2017-02-25 06:17:23
hey guys, I'm trying to install hledger, but I'm running into issues with hsc2hs: https://gist.github.com/Someguy123/2efd8dbaf6b057c070bf05c085e91bd8
Someguy123 2017-02-25 06:17:26
stack solver doesn't help, nor does adjusting the stack.yml
bollu 2017-02-25 06:17:28
(you can just post the link :) )
bollu 2017-02-25 06:17:37
yeah so
Aku 2017-02-25 06:17:42
ohhkay
Aku 2017-02-25 06:17:52
I have one more doubt
bollu 2017-02-25 06:18:01
sure
bollu 2017-02-25 06:18:02
go ahead
Aku 2017-02-25 06:18:30
[(combine v1 v2, toks2) | (v1,toks1) <- p1 toks, (v2, toks2) <- p2 toks1]
Aku 2017-02-25 06:18:41
consider that
bollu 2017-02-25 06:18:41
yes
bollu 2017-02-25 06:18:41
OK
Aku 2017-02-25 06:18:41
p1 toks returns a list
bollu 2017-02-25 06:18:47
correct
Aku 2017-02-25 06:18:55
but a writing the tuple (v1,toks1) <- p1 toks
bollu 2017-02-25 06:19:02
it returns a list of tuples
bollu 2017-02-25 06:19:10
so when you pattern match
Aku 2017-02-25 06:19:11
shouln't it be [(v1,toks1)] <- p1 toks
bollu 2017-02-25 06:19:14
no
bollu 2017-02-25 06:19:20
that's not the way the list pattern match works, right?
bollu 2017-02-25 06:19:26
> [x * 2| x <- [1..10]]
lambdabot 2017-02-25 06:19:29
[2,4,6,8,10,12,14,16,18,20]
c_wraith 2017-02-25 06:19:31
you can pretend <- strips off the top-level type constructor.
bollu 2017-02-25 06:19:36
we don't say [x] <- [1..10]
c_wraith 2017-02-25 06:19:49
It's not quite what really happens, but it's a good first intuition
Aku 2017-02-25 06:20:05
ohhkay
bollu 2017-02-25 06:20:10
c_wraith: it gets desugared to maps and filters right?
c_wraith 2017-02-25 06:20:26
bollu: in [], it's actually concatMap
bollu 2017-02-25 06:20:51
c_wraith: oh, right
bollu 2017-02-25 06:20:57
Aku: ok, well, so
Aku 2017-02-25 06:21:06
ya
bollu 2017-02-25 06:21:22
Aku: in (v1, toks1) <- p1 toks, the (v1, toks1) is a stand-in for _every_ tuple in the list
bollu 2017-02-25 06:21:28
it's like set builder notation
Aku 2017-02-25 06:21:38
ohh..there u go,got it
bollu 2017-02-25 06:21:43
OK
bollu 2017-02-25 06:21:47
so now
Aku 2017-02-25 06:21:59
lets proceed to pOneOrMore
bollu 2017-02-25 06:22:00
we were contemplating how to write one or more
bollu 2017-02-25 06:22:01
yeah
bollu 2017-02-25 06:22:16
we can say pOneOrMore p = pThen ??? p (pZeroOrMore p)
bollu 2017-02-25 06:22:29
do you agree that the types match first of all?
bollu 2017-02-25 06:22:32
(ignore the ??? for now)
Aku 2017-02-25 06:22:39
no bcoz pThen returns Parser p
bollu 2017-02-25 06:22:44
yes
bollu 2017-02-25 06:22:50
and what is the type of pOneOrMore?
Aku 2017-02-25 06:22:53
we want Parser [a]
bollu 2017-02-25 06:23:01
no, look at the type of pThen carefully
bollu 2017-02-25 06:23:07
it returns whatever we instruct it to
Aku 2017-02-25 06:23:09
I mean [[a],[Token]]
bollu 2017-02-25 06:23:11
with the first paramter
bollu 2017-02-25 06:23:31
Aku: err, I think you mean [([a], [Token])]
bollu 2017-02-25 06:23:33
but yeah
Aku 2017-02-25 06:23:37
yeah
bollu 2017-02-25 06:23:40
pThen :: (a->b->c) -> Parser a-> Parser b-> Parser c
bollu 2017-02-25 06:23:48
^ so the return type of the pThen (Parser c)
bollu 2017-02-25 06:23:51
is upto us to decide
Aku 2017-02-25 06:24:00
ya correct
bollu 2017-02-25 06:24:01
if we can combine the Parser a and Parser b in a "correct" way
bollu 2017-02-25 06:24:04
then we can make it work
bollu 2017-02-25 06:24:13
so in this case
Aku 2017-02-25 06:24:37
ya right
bollu 2017-02-25 06:24:49
let's see what we are forced to create
Aku 2017-02-25 06:24:49
yup
bollu 2017-02-25 06:24:49
pOneOrMore p = pThen foo p (pZeroOrMore p) | we shall figure out the type of "foo" now
bollu 2017-02-25 06:24:49
pThen :: (a->b->c) -> Parser a-> Parser b-> Parser c
bollu 2017-02-25 06:24:54
so, we know that pOneOrMore has return type "Parser [a]"
bollu 2017-02-25 06:25:02
so that means Parser c ~ Parser [a]
bollu 2017-02-25 06:25:04
agreed?
Aku 2017-02-25 06:25:08
agreed
bollu 2017-02-25 06:25:15
OK
bollu 2017-02-25 06:25:24
now we know that "p" has type Parser a
Aku 2017-02-25 06:25:30
yes
bollu 2017-02-25 06:25:37
so therefore Parser a ~ Parser a
Aku 2017-02-25 06:25:44
yesp
Aku 2017-02-25 06:25:46
yep
bollu 2017-02-25 06:25:48
we also know that (pZeroOrMore p) :: Parser [a]
bollu 2017-02-25 06:25:56
so therefore (Parser b ~ Parser [a]) ?
Aku 2017-02-25 06:26:00
yep
bollu 2017-02-25 06:26:03
hence
bollu 2017-02-25 06:26:13
the type of our invocation of pThen becomes
bollu 2017-02-25 06:26:26
pThen :: (a->b->c) -> Parser a-> Parser b-> Parser c where a = a, b = [a], c = [a]?
Aku 2017-02-25 06:26:38
yes
bollu 2017-02-25 06:26:39
which is
bollu 2017-02-25 06:26:55
pThen :: (a->[a]->[a]) -> Parser a-> Parser [a]-> Parser [a]?
bollu 2017-02-25 06:27:00
correct?
Aku 2017-02-25 06:27:03
yes
bollu 2017-02-25 06:27:12
so, now, we need to find out which foo :: a -> [a] -> [a] to use
bollu 2017-02-25 06:27:17
we know what we want pThen to do
Aku 2017-02-25 06:27:22
so foo::(a->[a]->[a])
bollu 2017-02-25 06:27:25
yes
Aku 2017-02-25 06:27:28
yep
bollu 2017-02-25 06:27:31
but now we need to find out _which_ foo to use
bollu 2017-02-25 06:27:32
now
Aku 2017-02-25 06:27:46
okay
bollu 2017-02-25 06:27:59
we know what (pOneOrMore p = pThen foo p (pZeroOrMore p) ) should do
bollu 2017-02-25 06:28:15
we need it to take the output of the "p" parser, and then prepend it to the "pZeroOrMore p"
bollu 2017-02-25 06:28:31
do you understand that bit?
bollu 2017-02-25 06:28:37
if not, I can explain
Aku 2017-02-25 06:28:47
hmm..right keeping the Token string returned unchanged!
Aku 2017-02-25 06:28:53
Is it?
bollu 2017-02-25 06:28:59
no, that's not the point
bollu 2017-02-25 06:29:01
the point is
bollu 2017-02-25 06:29:15
"foo" controls how the output of the first parser and the second parser are combined
Aku 2017-02-25 06:29:17
ya explain!
bollu 2017-02-25 06:29:17
in this case
Aku 2017-02-25 06:29:23
yes
bollu 2017-02-25 06:29:26
we know that our first parses parses first, then the second parser runs
Aku 2017-02-25 06:29:27
right
Aku 2017-02-25 06:29:33
yes
bollu 2017-02-25 06:29:33
so when we "fuse" the two parsers into one
Aku 2017-02-25 06:29:44
ya
bollu 2017-02-25 06:29:48
we need to take the output of the first parser, and *prepend* it to the list parsed by the second parser
bollu 2017-02-25 06:30:02
because the second parser produces a _list_ of output
Aku 2017-02-25 06:30:04
ya fine
bollu 2017-02-25 06:30:07
right?
Aku 2017-02-25 06:30:10
ya right
bollu 2017-02-25 06:30:11
so, we know what foo should to
Aku 2017-02-25 06:30:14
clear !
bollu 2017-02-25 06:30:15
should do*
bollu 2017-02-25 06:30:27
it should prepend the first parameter to the second parameter
bollu 2017-02-25 06:30:33
now, which is the haskell function that does this?
Aku 2017-02-25 06:30:34
ya
Aku 2017-02-25 06:30:44
:
bollu 2017-02-25 06:30:49
correct
bollu 2017-02-25 06:30:53
so our implementation becomes
Aku 2017-02-25 06:30:56
Cool!
bollu 2017-02-25 06:31:06
pOneOrMore = pThen (:) p (pZeroOrMore p)
bollu 2017-02-25 06:31:08
makes sense?
Aku 2017-02-25 06:31:12
This is awesome!
Aku 2017-02-25 06:31:18
yes..makes sense
bollu 2017-02-25 06:31:18
yeah :D
bollu 2017-02-25 06:31:22
parser combinators are slick
Aku 2017-02-25 06:31:30
Let me try out
bollu 2017-02-25 06:31:33
notice the cool thing: we are definition pZeroOrMore and pOneOrMore in terms of each other
bollu 2017-02-25 06:31:34
sure
Athas 2017-02-25 06:31:45
Hm, it looks like my happy-generatd parser segfaults.
Aku 2017-02-25 06:32:34
Ya also tell me how pEmpty works?
Aku 2017-02-25 06:32:47
and then overall pZeroOrMore!
Aku 2017-02-25 06:32:57
How it works!
Aku 2017-02-25 06:33:05
I want it to be crystal clear
bollu 2017-02-25 06:33:21
uh, paste the link again please
Aku 2017-02-25 06:33:27
ya
bollu 2017-02-25 06:33:27
pZeroOrMore is the same logic
Aku 2017-02-25 06:33:33
http://lpaste.net/5688715794511298560
bollu 2017-02-25 06:33:57
could you add pZeroOrMore and the rest of it into the file?
Aku 2017-02-25 06:34:13
It does not have it, its in the book, 'pEmpty'
bollu 2017-02-25 06:34:33
so implement it
Aku 2017-02-25 06:34:42
yes
bollu 2017-02-25 06:35:26
ok so
bollu 2017-02-25 06:35:29
I'm guessing
bollu 2017-02-25 06:35:41
pZeroOrMore p = pAlt pEmpty p?
bollu 2017-02-25 06:35:43
correct?
Aku 2017-02-25 06:36:21
yup
Aku 2017-02-25 06:36:23
correct
bollu 2017-02-25 06:36:30
yeah so
bollu 2017-02-25 06:36:32
basically
bollu 2017-02-25 06:36:37
wait, write the code in lpaste
bollu 2017-02-25 06:36:44
so we can concretely talk about it
Aku 2017-02-25 06:36:49
okay
Aku 2017-02-25 06:37:51
one sec...what are the arguements to pOneOrMore?
bollu 2017-02-25 06:38:07
it depends on how you write it
Aku 2017-02-25 06:38:10
its pOneOrMore p1 toks
bollu 2017-02-25 06:38:12
I take only the parser
bollu 2017-02-25 06:38:13
no
bollu 2017-02-25 06:38:16
we don't take the toks
bollu 2017-02-25 06:38:19
since we are building a parser
Aku 2017-02-25 06:38:22
ya you take the parser
bollu 2017-02-25 06:38:24
using the other combinators
Aku 2017-02-25 06:38:26
right
bollu 2017-02-25 06:38:38
we are not "defining" a parser by taking the [Token] in the "final" parser
Aku 2017-02-25 06:39:00
okay
Aku 2017-02-25 06:39:50
Thanks a lot bollu
bollu 2017-02-25 06:39:56
np
bollu 2017-02-25 06:40:01
yeah, no
bollu 2017-02-25 06:40:03
yeah, so*
bollu 2017-02-25 06:40:09
update the paste? :)
Aku 2017-02-25 06:40:10
The way you explained..just awesome!
Aku 2017-02-25 06:40:20
ya one min
bollu 2017-02-25 06:41:08
preludeDefs are used to have something to start to use the machine with BTW
lpaste_ 2017-02-25 06:41:32
Aku revised "pOneOrMore": "pOneOrMore" at http://lpaste.net/5688715794511298560
Aku 2017-02-25 06:42:15
Now i want to write pEmpty
bollu 2017-02-25 06:42:29
pEmpty does nothing
bollu 2017-02-25 06:42:30
it simply returns []
bollu 2017-02-25 06:42:57
wait, are you sure that is the signature?
bollu 2017-02-25 06:43:00
oh yeah
Aku 2017-02-25 06:44:10
yes
bollu 2017-02-25 06:44:18
OK
bollu 2017-02-25 06:44:18
so
bollu 2017-02-25 06:44:18
pempty doesn't "fail"
bollu 2017-02-25 06:44:18
it simply consumes no input
bollu 2017-02-25 06:44:18
which means
Aku 2017-02-25 06:44:18
ya I dont exaclty understand what pEmpty is doing
bollu 2017-02-25 06:44:18
pEmpty a input = [(a, input)]
Aku 2017-02-25 06:44:18
ya it consumes no input
bollu 2017-02-25 06:44:18
it simply "pretends" to have parsed the input
bollu 2017-02-25 06:44:18
and puts an "a" as the output
bollu 2017-02-25 06:44:18
it's a way of saying "don't take any input, but act like you have gotten this output from parsing"
Aku 2017-02-25 06:44:18
ohhkay
bollu 2017-02-25 06:44:18
this is required
bollu 2017-02-25 06:44:21
because we need a way to have an empty list be retuened from pZeroOrMore
bollu 2017-02-25 06:44:33
if we just did pZeroOrMore = pOneOrMore p
bollu 2017-02-25 06:44:43
this will fail if we have zero inputs
bollu 2017-02-25 06:44:45
so we say
bollu 2017-02-25 06:44:50
pZeroOrMore p = (pOneOrMore p) 'pAlt' (pEmpty [])
bollu 2017-02-25 06:44:51
which means
bollu 2017-02-25 06:44:56
"try to parse with one or more"
bollu 2017-02-25 06:45:33
"if this doesn't work, then pretend you parsed an empty list"
Aku 2017-02-25 06:45:33
okay what is the input to pEmpty?
bollu 2017-02-25 06:45:33
which is morally correct
Aku 2017-02-25 06:45:33
How to interpret that>
Aku 2017-02-25 06:45:33
?
bollu 2017-02-25 06:45:33
the input to pEmpty is what the parser should retun
bollu 2017-02-25 06:45:34
it's the output of the parser