cocreature 2017-02-25 00:46:03
flxw: there are two different reasons why people critisize fail: 1. it's part of Monad for historical reasons. eventually it will only be available in MonadFail but until then it's weird that every Monad has to supply a fail operation. 2. just being able to supply a string is kind of annoying. usually you want to use more structured types for your errors. for that you can use something like MonadError
flxw 2017-02-25 00:48:07
oh, I see. yeah, this is true. I'll have a look at monaderror now ...
dramforever 2017-02-25 00:51:37
MonadError is more like exceptions...
dramforever 2017-02-25 00:52:08
IIUC MonadFail for binds that may fail to pattern match. MonadError for exception-ish error handling
mryandao 2017-02-25 00:52:40
hi there, haskell newb here. I'm trying to figure out a compiler error with this code snippet -> https://0bin.net/paste/ZiTL6JblqF-bLWBX#gfu1DkpR0RVItaFl2W0VtzkV1vPoNvV3F-2WedYUL2a
mryandao 2017-02-25 00:53:47
here's a pastebin with the error
cocreature 2017-02-25 00:53:55
mryandao: remove the "do" outside the if and add one to the if clause of your if
mryandao 2017-02-25 00:53:55
https://0bin.net/paste/zxMziGbjJa45N-d-#W9SMI5xq9qs7Kv8ujdxtGG6BzsK1-3S7/uBise68RaI
cocreature 2017-02-25 00:54:41
the whole if is a single statement so putting do around it has no effect
mryandao 2017-02-25 00:54:43
oh i see
cocreature 2017-02-25 00:54:43
but if a < n you have two statements so you need "do"
mryandao 2017-02-25 00:55:54
argghh, i've been troubleshooting the types in ghci for a good hour
flxw 2017-02-25 00:57:48
btw, Is it considered bad style to write validation code inside the Parser monads? concretely: I am parsing log files, and building thyme values from the parsed timestamps. And at least for the moment, I want mal-formed timestamps (e.g. 31st of february) to be errors that abort the later stage of analysis.
sternmull 2017-02-25 00:59:53
i need a secure TCP-channel where both participants verify the identity of the other one. It seems hs-tls should do the job. Are there better examples than the ones in debug/src/? I don't think the API documentation is enough for me to get started.
cocreature 2017-02-25 01:01:37
flxw: I don't think that's bad at all. sometimes it is worth the effort to actually pull that validation code inside your parser, i.e., rely on the parser library to fail for mal-formed timestamps, but in a lot of cases (I would say timestamps fall in that category) parsing the timestamp just as a string and then validating it is significantly easier
dramforever 2017-02-25 01:03:30
flxw: You can first parse it into a general structure and refine it further later on
ongy 2017-02-25 01:04:35
sternmull: do you have a pki set up? otherwise the tls verification may be a bit annoying to set up for you
sternmull 2017-02-25 01:06:39
ongy: I think so. I want to store certificates on the participating machines and identify them by that. I have no use for a certificate chain or CAs. It just to securely connect to "services" that are managed by me. Just like i would connect to my systems using ssh.
sternmull 2017-02-25 01:07:58
but i want a kind of rpc and can not assume ssh is there. So i want to do it "manually" instead of using ssh.
ongy 2017-02-25 01:08:02
afaik you will need to set up a CA, but it's not that much work for a small system. Sadly I have no experience with hs-tls
flxw 2017-02-25 01:08:09
thank you both very much. Yes, in the end I think I will just drop invalid timestamps with a warning anyways. And then having several passes oover the parsed structure to refine it will be the better approach.
flxw 2017-02-25 01:10:01
sternmull: for debugging certificate and handshake issues openssl s_client is very helpful.
sternmull 2017-02-25 01:10:42
flxw: At the moment i am still looking for a minimal tls client-server example that i can use as a starting point.
flxw 2017-02-25 01:10:51
this way you could separate out the library issues from actual tls problems. :)
flxw 2017-02-25 01:11:39
would the example need to be in haskell per se?
sternmull 2017-02-25 01:12:52
Yes i want to use haskell for the implementation of the client and the server. I already have a python implementation but stopped with that to see if it is more fun to do it with haskell.
flxw 2017-02-25 01:13:04
I mean, I understand you want to use it in haskell, but for getting to know the tls api, C examples might be helpful, too?
flxw 2017-02-25 01:13:40
ah, okay.
sternmull 2017-02-25 01:14:42
flxw: I don't know if C code would help me to find my way into hs-tls. I know how to use tls in general, its really the haskell API that i have to understand.
flxw 2017-02-25 01:15:26
okay okay, I got that now. :)
sternmull 2017-02-25 01:16:05
But thanks for pointing out s_client. Looks like it will be helpful to test client/server on their own.
lpaste_ 2017-02-25 01:23:52
Aku pasted "How do I write pOneOrMore?" at http://lpaste.net/5476984330704125952
Aku 2017-02-25 01:24:46
Can someone look at my code, I want to write the function "pOneOrMore" as in the code?
bollu 2017-02-25 01:26:20
Aku: one sec
flxw 2017-02-25 01:26:20
yeah, because you don't need to hack in lots of debug code for tls stuff. I found this openssl tcp client pretty cool for separating my 'issues' from those of the tls library I'm using. In one case with a proprietary library, it turned out they left out the final newline from clear text certificates and so no certificate was ever valid. ...
Aku 2017-02-25 01:26:32
Ohh..bollu!
bollu 2017-02-25 01:26:50
Aku: oh hey :)
Aku 2017-02-25 01:27:12
Siddarth!
bollu 2017-02-25 01:27:23
yeah
Aku 2017-02-25 01:27:47
Its the same interpreter!
Aku 2017-02-25 01:28:11
There I am stuck at pOneOrMore!
sternmull 2017-02-25 01:28:13
flxw: Have you any experience with hs-tls? I wonder how it performs compared to openssl and others. But as long as it gets me at least around 100MiB/s everything would be fine.
flxw 2017-02-25 01:30:56
sternmull: No, not yet. But now I'm already curious about your findings. :) (and 100MiB/s should be doable, most desktop cpus have more than 2GHz clockrate nowadays ...)
bollu 2017-02-25 01:31:04
Aku: OK, so, describe to me what it must do in the first place
bollu 2017-02-25 01:31:10
Aku: then we will try and combinator it
bollu 2017-02-25 01:31:52
Aku: so, what are the semantics of pOneOrMore?
sternmull 2017-02-25 01:31:54
flxw: Ok, i will tell you my results when/if i get it running.
bollu 2017-02-25 01:32:06
Aku: if I may make a suggestion: first implement pZeroOrMore
Aku 2017-02-25 01:32:26
bollu can you just open page 35 of 'Implementing functional languages, a tutorial?'
bollu 2017-02-25 01:32:36
uh, sure
bollu 2017-02-25 01:32:41
give me a minute
bollu 2017-02-25 01:32:45
sort of in the middle of something
bollu 2017-02-25 01:32:50
Aku: but, I want _you_ to explain to me
flxw 2017-02-25 01:32:55
sternmull: Cool, thank you. hehe
bollu 2017-02-25 01:33:32
Aku: also, calling me by "real name" on IRC is a little… :)
Aku 2017-02-25 01:33:41
I am srry!
bollu 2017-02-25 01:33:55
yes, I'm at the page
bollu 2017-02-25 01:34:05
Aku: OK, he defines zero or more using one or more
bollu 2017-02-25 01:34:26
Aku: OK, neat, he uses mututally recursive definitions
Aku 2017-02-25 01:34:29
Apologies...so it should give me a list of successive application of p
bollu 2017-02-25 01:34:29
which is slick
bollu 2017-02-25 01:34:31
but.. a little weird to see
bollu 2017-02-25 01:34:35
YES
bollu 2017-02-25 01:34:37
Yes*
bollu 2017-02-25 01:35:13
Aku: so yes
bollu 2017-02-25 01:35:27
Aku: it should "try" the parser many times, but the parser should succeed at least once
Aku 2017-02-25 01:35:42
ya correct
bollu 2017-02-25 01:35:50
can you link me to your code again?
Aku 2017-02-25 01:36:03
Yes..sure
lpaste_ 2017-02-25 01:36:22
Aku revised "How do I write pOneOrMore?": "How do I write pOneOrMore?" at http://lpaste.net/5476984330704125952
bollu 2017-02-25 01:36:45
OK so
Aku 2017-02-25 01:36:46
This is the full cod
bollu 2017-02-25 01:36:46
first of all
Aku 2017-02-25 01:36:50
*code
bollu 2017-02-25 01:36:52
we need to return a parser
Aku 2017-02-25 01:37:06
Ya that's where I am stuck
Aku 2017-02-25 01:37:14
How to return a parser?
bollu 2017-02-25 01:37:47
Aku: OK
bollu 2017-02-25 01:38:02
Aku: how does pThen work?
bollu 2017-02-25 01:38:18
Aku: as in, how does pThen return a parser?
Aku 2017-02-25 01:38:20
Also I don't exactly understand the type Paser [a]
bollu 2017-02-25 01:38:34
OK
bollu 2017-02-25 01:38:38
let us start from there first
bollu 2017-02-25 01:38:43
what is "Parser p"?
Aku 2017-02-25 01:38:48
Ya pThen applies p1 then p2 to remaining tokens
bollu 2017-02-25 01:39:10
Aku: wait, tell me what "Parser p" is
bollu 2017-02-25 01:39:57
Aku: ?
Aku 2017-02-25 01:40:04
Ya ...one min
Aku 2017-02-25 01:40:31
Parser p checks whether the list contains anything of type p
bollu 2017-02-25 01:40:47
no, just tell me what the type "Parser p" actually is
bollu 2017-02-25 01:40:54
Parser p is a type alias right?
Aku 2017-02-25 01:40:59
Ya ya
bollu 2017-02-25 01:41:01
what is the "underlying" type?
Aku 2017-02-25 01:41:05
correct
Aku 2017-02-25 01:41:32
a production rule
Aku 2017-02-25 01:41:42
Underlying type^
bollu 2017-02-25 01:41:59
type Parser a = [Token] -> [(a,[Token])]
bollu 2017-02-25 01:42:06
I was hoping for an answer of [Token] -> [(a,[Token])]
bollu 2017-02-25 01:42:16
because "Parser a" is sugar for [Token] -> [(a,[Token])]
Aku 2017-02-25 01:42:26
oops..I thought you read it!
bollu 2017-02-25 01:42:30
I did
bollu 2017-02-25 01:42:33
but I'm asking you
bollu 2017-02-25 01:42:40
so pretend I haven't read it
Aku 2017-02-25 01:42:49
ohh..srry
bollu 2017-02-25 01:42:54
it's okay
bollu 2017-02-25 01:42:55
okay so
bollu 2017-02-25 01:43:00
that is what Parser a is, right?
bollu 2017-02-25 01:43:10
so, what does "Parser a" *represent* ?
Aku 2017-02-25 01:43:10
yup
bollu 2017-02-25 01:43:18
interpret the type [Token] -> [(a,[Token])] for me
bollu 2017-02-25 01:43:59
like, what does the type *mean*?
Aku 2017-02-25 01:44:08
It takes in a list of tokens which are of type string and returns another list
bollu 2017-02-25 01:44:14
sure
Aku 2017-02-25 01:44:14
type means just an alias
bollu 2017-02-25 01:44:16
but, like
bollu 2017-02-25 01:44:27
what is the list of tokens it takes, and what is return list
bollu 2017-02-25 01:44:40
something along the line of "it takes the raw stream of tokens, and returns …"
Aku 2017-02-25 01:44:44
just a min...
bollu 2017-02-25 01:44:46
sure
bollu 2017-02-25 01:44:53
(you can refer to the book BTW)
bollu 2017-02-25 01:45:02
I'm doing this to make sure you understand what our types represent
Aku 2017-02-25 01:46:13
Still it's not clear fully
bollu 2017-02-25 01:46:59
OK
bollu 2017-02-25 01:47:04
is the question not clear?
Aku 2017-02-25 01:47:04
I mean what are you expecting?
bollu 2017-02-25 01:47:04
OK
bollu 2017-02-25 01:47:04
so, if I tell you "Parser a"
bollu 2017-02-25 01:47:04
what does "Parser a" do?
Aku 2017-02-25 01:47:07
so Parser Int will take [Token] -> [Int,[Token]]