Logs: liberachat/#haskell
| 2021-06-09 14:46:42 | <delYsid> | is there a way to wrap this up without creating *two* internal modules? |
| 2021-06-09 14:46:43 | <gentauro_> | «Early June 8, a customer pushed *a valid configuration* change that included the specific circumstances that triggered the bug, which caused 85% of our network to return errors.» so a type error xD https://www.fastly.com/blog/summary-of-june-8-outage |
| 2021-06-09 14:47:08 | <c_wraith> | delYsid: you could define r locally instead of at the top level |
| 2021-06-09 14:47:20 | <delYsid> | ah |
| 2021-06-09 14:47:42 | × | bontaq quits (~user@ool-18e47f8d.dyn.optonline.net) (Ping timeout: 252 seconds) |
| 2021-06-09 14:47:45 | <tdammers> | obvious fix: grep for the number 85 in the codebase, and change all occurrences to 0 |
| 2021-06-09 14:48:41 | <merijn> | delYsid: You don't wanna $( the AppE, you just return that |
| 2021-06-09 14:48:59 | <merijn> | At least, I think you don't |
| 2021-06-09 14:49:11 | <merijn> | ah, wait, I see what's you're doing |
| 2021-06-09 14:49:34 | <delYsid> | I think the problem is Exp vs TExp |
| 2021-06-09 14:49:39 | <merijn> | delYsid: You wanna get rid of the outer $( and the use "$(x filepath)" somewhere |
| 2021-06-09 14:49:55 | → | bontaq` joins (~user@ool-18e47f8d.dyn.optonline.net) |
| 2021-06-09 14:50:28 | <merijn> | delYsid: Ah, you're mixing typed and untyped TH too |
| 2021-06-09 14:50:43 | <merijn> | $$( is typed TH, but $( and [| are untyped TH |
| 2021-06-09 14:50:49 | → | benin03 joins (~benin@183.82.205.134) |
| 2021-06-09 14:50:57 | × | benin03 quits (~benin@183.82.205.134) (Client Quit) |
| 2021-06-09 14:51:05 | <merijn> | delYsid: "lift $$(r fp)" is also suspificous |
| 2021-06-09 14:51:20 | <merijn> | That looks like you just want "r fp", tbh |
| 2021-06-09 14:51:21 | <delYsid> | yeah, I told you TH confuses me. |
| 2021-06-09 14:51:23 | <delYsid> | But I am close |
| 2021-06-09 14:51:37 | <delYsid> | AIUI, I have TExp cos I use liftTyped |
| 2021-06-09 14:51:49 | <delYsid> | But I dunno how to get rid of it, $$(...) seemed to do the trick |
| 2021-06-09 14:52:15 | <merijn> | delYsid: Let's rewind a bit. Part of the confusingness of TH is that you have *2* "runtimes" (the "runtime" of code that runs at compile time and "normal" runtime) |
| 2021-06-09 14:52:29 | × | fluffyballoon quits (~fluffybal@2620:72:0:6480::10f7) (Quit: Client closed) |
| 2021-06-09 14:52:35 | <delYsid> | No instance for (Lift (Q (TExp [Opening]))) |
| 2021-06-09 14:52:50 | <merijn> | delYsid: The code that runs at compile time is just regular old boring Haskell. But it needs to (in the end) produce an AST that GHC "inserts" into the code that is being compiled |
| 2021-06-09 14:53:06 | <merijn> | delYsid: The Q monad let's you 1) do IO and 2) query GHC about code/types |
| 2021-06-09 14:53:08 | <delYsid> | I get that part |
| 2021-06-09 14:53:38 | <merijn> | delYsid: $(x) takes "Q (TExp a)" and splices the AST produced by that Q action into that part of the code |
| 2021-06-09 14:54:15 | <merijn> | delYsid: So "lift $$(r fp)" first runs 'r fp' (at compile time), then splices the AST into the code |
| 2021-06-09 14:54:16 | <delYsid> | It only worked when I used $$, but I was only trying it out in ghci, so maybe the repl differs? |
| 2021-06-09 14:54:49 | <merijn> | but then 'lift' tries to turn that AST into an AST again |
| 2021-06-09 14:55:20 | × | gentauro_ quits (~gentauro@user/gentauro) (Quit: leaving) |
| 2021-06-09 14:55:21 | <delYsid> | Couldn't match type ‘TExp [Opening]’ with ‘Exp’ |
| 2021-06-09 14:55:25 | <merijn> | delYsid: So you end up trying to splice the AST of "Q (TExp a)" into your code |
| 2021-06-09 14:55:31 | <merijn> | delYsid: Ok, that is easy to fix |
| 2021-06-09 14:55:35 | → | gentauro joins (~gentauro@user/gentauro) |
| 2021-06-09 14:55:51 | <merijn> | delYsid: Replace "[| x |]" with "[|| x ||]" |
| 2021-06-09 14:56:11 | <merijn> | ([|| ||] is the typed quotes vs [| |] which produces untyped quotes) |
| 2021-06-09 14:56:27 | <delYsid> | Couldn't match type ‘TExp (Q (TExp [Opening]))’ with ‘Exp’ |
| 2021-06-09 14:56:28 | bontaq` | is now known as bontaq |
| 2021-06-09 14:56:35 | <merijn> | can you pastebin the code? |
| 2021-06-09 14:57:22 | <delYsid> | to be honest, no. I am stuck on a console |
| 2021-06-09 14:58:33 | <delYsid> | The problem is still typed vs untyped, just that [|| x ||] doesnt help because I have no x, I have "r fp" which is Q (TExp [Opening]) |
| 2021-06-09 14:58:46 | <merijn> | hold, lemme slap something together |
| 2021-06-09 14:59:16 | → | slowButPresent joins (~slowButPr@user/slowbutpresent) |
| 2021-06-09 14:59:33 | → | Lycurgus joins (~juan@cpe-45-46-140-49.buffalo.res.rr.com) |
| 2021-06-09 14:59:46 | <merijn> | And then break it down |
| 2021-06-09 15:00:04 | <merijn> | https://paste.tomsmeding.com/l6B1l0Pj |
| 2021-06-09 15:00:22 | <merijn> | Ok, so the 'r' there is just regular boring old Haskell you know how to write, right? |
| 2021-06-09 15:01:16 | <delYsid> | https://blind.guru/TH.hs |
| 2021-06-09 15:01:27 | × | maerwald quits (~maerwald@user/maerwald) (Ping timeout: 252 seconds) |
| 2021-06-09 15:01:30 | <merijn> | delYsid: Let's breakdown 'x', first we liftIO your boring old IO code into the Q monad. This means we execute *all* of 'r' at compile time (probably 'r' needs to be in a different module from 'x' due to stage restriction) |
| 2021-06-09 15:02:04 | Lycurgus | just found googling "legible haskell" amusing |
| 2021-06-09 15:02:05 | × | mastarija__ quits (~mastarija@46.188.129.109) (Quit: Leaving) |
| 2021-06-09 15:02:23 | <merijn> | So, 'x' is a TH function that produces a (typed) AST that represents a value of type 'YourType' |
| 2021-06-09 15:02:32 | <merijn> | delYsid: Let's look at the parts |
| 2021-06-09 15:02:33 | → | maerwald joins (~maerwald@mail.hasufell.de) |
| 2021-06-09 15:02:43 | × | maerwald quits (~maerwald@mail.hasufell.de) (Changing host) |
| 2021-06-09 15:02:43 | → | maerwald joins (~maerwald@user/maerwald) |
| 2021-06-09 15:02:51 | <merijn> | "AppE" is a constructor from Exp which represents function application |
| 2021-06-09 15:03:18 | <delYsid> | get that |
| 2021-06-09 15:03:35 | × | favonia quits (~favonia@user/favonia) (Ping timeout: 272 seconds) |
| 2021-06-09 15:03:48 | <merijn> | [|| fromList ||] turns the 'fromList' function into 'Q (TExp (a -> b))', i.e. a quasiquote representing a function (probably 'Q (TExp ([k, v] -> HashMap k v)' here) |
| 2021-06-09 15:04:13 | → | favonia joins (~favonia@user/favonia) |
| 2021-06-09 15:04:16 | <merijn> | So we somehow need to get an AST for [(k, v)] to which we can apply fromList |
| 2021-06-09 15:04:38 | <merijn> | delYsid: But what you *have* is not the AST for [(k, v)], but an *actual* list that 'r' just parsed |
| 2021-06-09 15:05:08 | <merijn> | delYsid: So we need a function that goes '[(k, v)] -> Q (TExp [(k, v)])' |
| 2021-06-09 15:05:22 | <merijn> | delYsid: Which is what liftTyped does |
| 2021-06-09 15:05:48 | <c_wraith> | on sufficiently recent versions of GHC... |
| 2021-06-09 15:05:54 | <merijn> | Now, since we have AppE and Q is a monad we can do our regular Applicative dance to combine them |
| 2021-06-09 15:05:58 | <c_wraith> | I'm a bit sad how recent liftTyped is |
| 2021-06-09 15:06:00 | → | eggplantade joins (~Eggplanta@2600:1700:bef1:5e10:2121:a570:d35e:ba7a) |
| 2021-06-09 15:06:02 | <merijn> | c_wraith: Same |
| 2021-06-09 15:06:18 | <merijn> | c_wraith: But at least it's here now! |
| 2021-06-09 15:07:12 | ski | . o O ( "Cross-stage persistence" <http://okmij.org/ftp/ML/MetaOCaml.html#CSP> ) |
| 2021-06-09 15:07:14 | <merijn> | delYsid: So now that we have 'x' this way, all we need to do to embed your data is call (and splice the result) of 'x' into your actual code, which you'd do using something like 'compileTimeMap = $$(x "path/to/file")' in your code |
| 2021-06-09 15:08:04 | <merijn> | delYsid: There's one catch, though. Which is: you cannot call code in the same module as 'x' from 'x' (so your 'r' function needs to be in a different module) and you cannot call 'x' in the module you define it (the stage restriction error before) |
| 2021-06-09 15:08:31 | <merijn> | delYsid: Because GHC has to compile 'r' before it can compile 'x' and needs to compile 'x' before you can use it and doing that in the same module is hard |
| 2021-06-09 15:09:22 | <delYsid> | Since I dont need r, is there a way to write x such that I dont need a second module? |
| 2021-06-09 15:09:37 | × | Scotty_Trees quits (~Scotty_Tr@162-234-179-169.lightspeed.brhmal.sbcglobal.net) (Quit: Leaving) |
| 2021-06-09 15:10:10 | <merijn> | delYsid: Sure, you can have the code of 'r' inside 'x' itself, if it only uses library code |
| 2021-06-09 15:10:30 | × | eggplantade quits (~Eggplanta@2600:1700:bef1:5e10:2121:a570:d35e:ba7a) (Ping timeout: 264 seconds) |
| 2021-06-09 15:11:10 | → | Scotty_Trees joins (~Scotty_Tr@162-234-179-169.lightspeed.brhmal.sbcglobal.net) |
| 2021-06-09 15:11:58 | <merijn> | delYsid: Something like https://paste.tomsmeding.com/NBPCg1ip |
| 2021-06-09 15:12:13 | <merijn> | delYsid: assuming parseList is defined in another module |
| 2021-06-09 15:12:25 | <delYsid> | I always hit the same issue. I have a TExp but my AppE wants an Exp |
| 2021-06-09 15:12:58 | <delYsid> | the modern web is driving me crazy. try "lynx https://paste.tomsmeding.com/NBPCg1ip" and be welcome in my world. |
| 2021-06-09 15:13:19 | → | wroathe_ joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-06-09 15:13:30 | → | chele_ joins (~chele@user/chele) |
| 2021-06-09 15:13:31 | → | fendor_ joins (~fendor@178.165.130.85.wireless.dyn.drei.com) |
| 2021-06-09 15:14:18 | × | pavonia quits (~user@user/siracusa) (Read error: Connection reset by peer) |
| 2021-06-09 15:14:26 | → | hiptobecubic joins (~john@c-73-55-99-95.hsd1.fl.comcast.net) |
| 2021-06-09 15:14:30 | → | ell4 joins (~ellie@user/ellie) |
| 2021-06-09 15:15:02 | → | kw` joins (~user@152.1.137.158) |
| 2021-06-09 15:15:17 | → | nilof joins (~olofs@90-227-86-119-no542.tbcn.telia.com) |
| 2021-06-09 15:15:32 | × | chele quits (~chele@user/chele) (Killed (lithium.libera.chat (Nickname regained by services))) |
| 2021-06-09 15:15:32 | chele_ | is now known as chele |
| 2021-06-09 15:15:52 | → | laguneucl joins (~Pitsikoko@2a02:587:dc02:b00:98b0:cd42:bd6f:8295) |
| 2021-06-09 15:16:05 | × | wroathe_ quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Client Quit) |
All times are in UTC.