shiona 2017-01-28 02:49:03
any idea why Wreq get receives a completely different answer compared to a curl from the same machine?
srhb 2017-01-28 02:50:28
shiona: Different headers?
srhb 2017-01-28 02:50:44
shiona: Tried dumping the request with netcat or something similar?
shiona 2017-01-28 02:51:03
I tried setting user agent. I hope wreq does set Host automatically
shiona 2017-01-28 02:51:20
the last thing left seems Accept-Encoding. I guess it's worth a shot
shiona 2017-01-28 02:51:51
oh, wait. That was the wreq request that had the Host set.
shiona 2017-01-28 02:54:37
.. does wreq automatically follow 302's? that might be my problem
srhb 2017-01-28 02:57:46
shiona: You can try making culr do the same with -L
shiona 2017-01-28 02:58:40
I'm making a "isLoggedIn" function, that tries to load a page that for non-logged-in users will return a 302
shiona 2017-01-28 02:59:06
and it seems "redirectCount" in HTTP.Client is what i need
srhb 2017-01-28 03:00:19
shiona: there's a redirects lens in wreq too, if you just want to limit the maximum amount.
shiona 2017-01-28 03:00:46
ok, maybe that's a cleaner choice
ph88 2017-01-28 03:13:30
when i have data Foo = F (Maybe (String)) is it possible to put (Maybe (String)) into a function ?
ertes 2017-01-28 03:15:00
shiona: wreq has to set Host properly, because not doing so violates HTTP 1.1
shiona 2017-01-28 03:15:15
I know ^^
shiona 2017-01-28 03:15:28
I was just baffled on why it wasn't working
shiona 2017-01-28 03:15:46
turns out wreq just outsmarted me, so I had to make it dumber
ertes 2017-01-28 03:15:59
ph88: what do you mean?
ph88 2017-01-28 03:16:24
something like bar = (Maybe (String)) data Foo = F bar ?
ertes 2017-01-28 03:16:43
ph88: you can make it a type alias: type Bar = Maybe String
ertes 2017-01-28 03:16:46
data Foo = F Bar
ph88 2017-01-28 03:16:52
oooh yes good idea !
ph88 2017-01-28 03:16:58
thank you ertes
ertes 2017-01-28 03:17:13
ph88: of course in this particular case i wouldn't do that… if you need documentation, give the field a name
ertes 2017-01-28 03:17:26
data Foo = F { fieldName :: Maybe String }
ertes 2017-01-28 03:17:59
also you likely want a newtype there: newtype Foo = F { fieldName :: Maybe String }
ph88 2017-01-28 03:18:08
data ProcessStatement = MkProcessStatement (Maybe ((NT Label), T)) (Maybe T) T i have types like this and the first field (Maybe ((NT Label), T)) is shared between many data types
ertes 2017-01-28 03:18:31
ah
ertes 2017-01-28 03:19:16
ph88: style note: Maybe (NT Label, T)
ph88 2017-01-28 03:19:44
so maybe i can do something like type P_Label = Maybe ((NT Label), T) and then data ProcessStatement = MkProcessStatement P_Label (Maybe T) T
ph88 2017-01-28 03:21:03
i didn't want to use records because initially i had lot's of functions with similar names as i would give to the field selector functions. But this actually changed because i'm using a typeclass now so i, you think it's better to use records ?
ertes 2017-01-28 03:21:21
ph88: another side note: one of the most awkward features of the sample-frame library is that it uses types named T =)
ph88 2017-01-28 03:21:28
i already wrote like 2000 lines of code though, so it would be a bit painful change ^^
ertes 2017-01-28 03:22:12
ph88: what's T?
ph88 2017-01-28 03:22:19
ertes, i'm not familiar with the sample-frame library, T is my type, it stands for Terminal, but i renamed it to T so that the lines length doesn't get too big
ertes 2017-01-28 03:22:32
ph88: there is a more powerful way to do that
ertes 2017-01-28 03:22:56
ph88: data ProcessStatement a = MkProcessStatement (Maybe (NT Label, a)) (Maybe a) a
ertes 2017-01-28 03:23:07
ph88: now you can write: deriving (Foldable, Functor, Traversable)
ph88 2017-01-28 03:23:46
ah yes this could be useful later one when i have alternative implementations of Terminal
ertes 2017-01-28 03:24:17
ph88: gives you lovely idioms like: traverse createTerm (MkProcessStatement Nothing (Just "path1") "path2")
ph88 2017-01-28 03:24:55
what's that ?
ertes 2017-01-28 03:25:50
ph88: uses 'createTerm' on each of the 'a's and gives you a ProcessStatement populated respectively
ertes 2017-01-28 03:27:26
ph88: here is a different way to express this: let actions = MkProcessStatement Nothing (Just (createTerm "path1")) (createTerm "path2")
ertes 2017-01-28 03:27:33
actions :: ProcessStatement (IO ())
ertes 2017-01-28 03:27:55
whoops
ertes 2017-01-28 03:27:59
actions :: ProcessStatement (IO Terminal)
ertes 2017-01-28 03:28:10
sequenceA :: ProcessStatement (IO Terminal) -> IO (ProcessStatement Terminal)
ertes 2017-01-28 03:28:36
sequenceA actions -- gives you a (ProcessStatement Terminal) with two terminals
ertes 2017-01-28 03:33:13
ph88: if you happen to have lenses for Terminal, you can also exploit 'traverse' the following way:
ertes 2017-01-28 03:33:29
termFd :: Lens' Terminal Fd
ertes 2017-01-28 03:33:52
traverseOf (traverse . termFd) hClose :: ProcessStatement Terminal -> IO () -- close all file handles
ph88 2017-01-28 03:33:52
ertes, i understand what it does now, but why would i need this for my program ?
ertes 2017-01-28 03:35:32
ph88: well, i imagine that you create ProcessStatements similar to this currently: do t1 <- createTerm cfg1; t2 <- createTerm cfg2; pure (MkProcessStatement Nothing (Just t1) t2)
ertes 2017-01-28 03:36:11
ph88: if ProcessStatement is Traversable, you can do this instead: traverse createTerm (MkProcessStatement Nothing (Just cfg1) cfg2)
ph88 2017-01-28 03:38:01
ertes, here is an example of what i do, this one mixes non-terminals with terminals https://paste.fedoraproject.org/538120/85614238/ but there are also rules that have only terminals, or rules that have only non-terminals
ertes 2017-01-28 03:39:31
ph88: ok, let me explain this with a different example:
ertes 2017-01-28 03:40:04
you have a list of file paths 'fps' and an action that takes a file path and returns contents of the file
ertes 2017-01-28 03:40:07
fps :: [FilePath]
ertes 2017-01-28 03:40:14
readFile :: FilePath -> IO Text
ertes 2017-01-28 03:40:41
'traverse' takes those two and returns a structurally equivalent list of file contents
ertes 2017-01-28 03:40:49
traverse readFile fps :: [Text]
ertes 2017-01-28 03:40:58
now generalise "list" to "F"
ertes 2017-01-28 03:41:36
ProcessStatement is your F
ph88 2017-01-28 03:43:56
ertes, i could that .. just saying i don't know how this technique would fit in with what i'm currently doing
ph88 2017-01-28 03:44:41
i got that *