Logs: freenode/#haskell
| 2021-04-06 11:01:35 | → | jonathanx joins (~jonathan@h-176-109.A357.priv.bahnhof.se) |
| 2021-04-06 11:01:40 | <merijn> | Lift is the typeclass for "values that can be written as source literals" |
| 2021-04-06 11:01:51 | <merijn> | Type is not something that has values |
| 2021-04-06 11:02:02 | <olligobber> | isn't it? |
| 2021-04-06 11:02:05 | <merijn> | Sounds like you want something like reify or something |
| 2021-04-06 11:02:10 | <merijn> | olligobber: no? |
| 2021-04-06 11:02:20 | <merijn> | What values does type have? |
| 2021-04-06 11:02:30 | × | LiaoTao quits (~LiaoTao@gateway/tor-sasl/liaotao) (Remote host closed the connection) |
| 2021-04-06 11:02:35 | <olligobber> | https://hackage.haskell.org/package/template-haskell-2.17.0.0/docs/Language-Haskell-TH.html#g:22 |
| 2021-04-06 11:02:52 | → | LiaoTao joins (~LiaoTao@gateway/tor-sasl/liaotao) |
| 2021-04-06 11:03:05 | <merijn> | Wait |
| 2021-04-06 11:03:11 | <olligobber> | VarT (Name "Int") ? |
| 2021-04-06 11:03:18 | <merijn> | You're constructing TH *in* TH? |
| 2021-04-06 11:03:27 | <olligobber> | no? |
| 2021-04-06 11:03:41 | <merijn> | olligobber: Then you're very confused ;) |
| 2021-04-06 11:04:00 | → | mkDoku joins (~TheMule@aftr-37-201-195-134.unity-media.net) |
| 2021-04-06 11:04:01 | <olligobber> | D: |
| 2021-04-06 11:04:04 | <merijn> | olligobber: Let's rewind |
| 2021-04-06 11:04:06 | × | Guest63000 quits (~textual@2603-7000-3040-0000-e045-d645-2e21-7cec.res6.spectrum.com) (Ping timeout: 245 seconds) |
| 2021-04-06 11:04:30 | <merijn> | So, we have Template Haskell which is code, that runs at compile time and produces an AST (that gets compiled into the final program) |
| 2021-04-06 11:04:40 | <olligobber> | yes |
| 2021-04-06 11:04:43 | <merijn> | That AST is represented as Type |
| 2021-04-06 11:05:12 | <olligobber> | part of it is, sure |
| 2021-04-06 11:05:20 | → | frozenErebus joins (~frozenEre@37.231.244.249) |
| 2021-04-06 11:05:38 | → | Alleria_ joins (~textual@2603-7000-3040-0000-e045-d645-2e21-7cec.res6.spectrum.com) |
| 2021-04-06 11:05:49 | <olligobber> | oh |
| 2021-04-06 11:05:51 | <olligobber> | hm |
| 2021-04-06 11:05:52 | <merijn> | The Lift class has, essentially, 1 function: "liftTyped :: t -> m Exp" |
| 2021-04-06 11:06:11 | × | tromp quits (~tromp@dhcp-077-249-230-040.chello.nl) (Read error: No route to host) |
| 2021-04-06 11:06:13 | × | acidjnk_new quits (~acidjnk@p200300d0c72b95396118d8d56ee70ad6.dip0.t-ipconnect.de) (Ping timeout: 250 seconds) |
| 2021-04-06 11:06:19 | <merijn> | i.e. "given a value (at TH execution time), give me the AST representating that value" |
| 2021-04-06 11:06:40 | <olligobber> | I fixed it! |
| 2021-04-06 11:06:47 | → | tromp joins (~tromp@dhcp-077-249-230-040.chello.nl) |
| 2021-04-06 11:06:48 | <olligobber> | now I get a different error |
| 2021-04-06 11:07:01 | <sshine> | merijn, "liftTyped" as in "it passed GHC's type-check"? |
| 2021-04-06 11:07:03 | <merijn> | But, trying to Lift "Type" implies you are trying to construct the AST of a TH AST at compile time |
| 2021-04-06 11:07:07 | × | rprije quits (~rprije@59-102-63-15.tpgi.com.au) (Ping timeout: 260 seconds) |
| 2021-04-06 11:07:12 | <olligobber> | yeah I was |
| 2021-04-06 11:07:25 | <merijn> | sshine: Well, there's "two" THs in GHC |
| 2021-04-06 11:07:48 | <olligobber> | instead I used a let bind to make it lift the string instead of the Type |
| 2021-04-06 11:07:52 | <merijn> | sshine: There's regular old Template Haskell, which is a Haskell AST that gets compiled, but that AST might be broken and have type errors |
| 2021-04-06 11:08:10 | × | jpds quits (~jpds@gateway/tor-sasl/jpds) (Remote host closed the connection) |
| 2021-04-06 11:08:12 | <merijn> | sshine: There's also Typed TH which guarantees the TH generated AST is well-typed |
| 2021-04-06 11:08:18 | × | hpc quits (~juzz@ip98-169-35-13.dc.dc.cox.net) (Ping timeout: 240 seconds) |
| 2021-04-06 11:08:25 | <sshine> | merijn, cool! |
| 2021-04-06 11:08:33 | <merijn> | sshine: So really it's more like "liftTyped :: t -> Q (TExp t)" |
| 2021-04-06 11:08:34 | <olligobber> | yeah, I can't use typed th here |
| 2021-04-06 11:08:44 | <merijn> | sshine: vs "lift :: t -> Q Exp" |
| 2021-04-06 11:08:50 | <sshine> | merijn, so supposedly that reduces the C++-like type-error-wall-of-text scenarios? |
| 2021-04-06 11:09:12 | <merijn> | sshine: It means that you get the type error in your TH code, rather then the *generated* code, yeah |
| 2021-04-06 11:09:19 | <merijn> | sshine: Also, it allows some funky hacks |
| 2021-04-06 11:09:31 | <merijn> | sshine: Because you can smuggle typeclass instances backwards! |
| 2021-04-06 11:09:56 | <olligobber> | merijn, so I was basically doing [| show t |] where t :: Type, but now I'm doing let showt = show t in [| showt |] |
| 2021-04-06 11:10:08 | <sshine> | merijn, >_< |
| 2021-04-06 11:10:09 | <merijn> | @hackage validated-literals |
| 2021-04-06 11:10:09 | <lambdabot> | https://hackage.haskell.org/package/validated-literals |
| 2021-04-06 11:10:35 | <merijn> | sshine: I take a look at the "final" type, then smuggle the typeclass from that back to compile time to do validation |
| 2021-04-06 11:11:16 | <merijn> | I need to update it for 9.0, 9.2 and TH 2.17 though >.> |
| 2021-04-06 11:11:17 | <olligobber> | ok, now to make "ForallT [KindedTV a_6989586621679019993 StarT,KindedTV v_7566047373982443483 StarT] [] (AppT (AppT (ConT Functional.Lambda.Typed.TypedLambda) (AppT (AppT ArrowT (VarT a_6989586621679019993)) (VarT a_6989586621679019993))) (VarT v_7566047373982443483))" into something readable |
| 2021-04-06 11:11:58 | <sshine> | merijn, validated-literals is a good example of somewhere where the type-level fu is pretty encapsulated, and the exposed interface is clean and Boring in the exciting way. :-D |
| 2021-04-06 11:12:08 | <merijn> | sshine: Thanks :D |
| 2021-04-06 11:12:13 | <merijn> | That was the goal |
| 2021-04-06 11:12:23 | <merijn> | tbh |
| 2021-04-06 11:12:25 | <olligobber> | yeah, validated-literals is super cool |
| 2021-04-06 11:12:29 | <merijn> | the implementation is trivial |
| 2021-04-06 11:12:34 | <sshine> | I've seen it before. I just haven't used it yet. so nice to get reminded. |
| 2021-04-06 11:13:04 | → | jpds joins (~jpds@gateway/tor-sasl/jpds) |
| 2021-04-06 11:14:05 | <merijn> | I'm trying to sneak in enough hacking time to fix Haskell-CI to my liking for GitHub Actions so I can restore CI testing on my repos and update for GHC 9.0 and later, but coding energy is low stuck at home all year >.> |
| 2021-04-06 11:14:26 | → | hpc joins (~juzz@ip98-169-35-13.dc.dc.cox.net) |
| 2021-04-06 11:14:41 | × | Alleria_ quits (~textual@2603-7000-3040-0000-e045-d645-2e21-7cec.res6.spectrum.com) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2021-04-06 11:14:56 | <olligobber> | ah, pprint, nice: `forall (a_0 :: *) (v_1 :: *) .Functional.Lambda.Typed.TypedLambda (a_0 -> a_0) v_1' |
| 2021-04-06 11:16:05 | <merijn> | olligobber: I can't help but be suspicious of showing a type, then quoting that? Really seems like you'd want something like Name or reify instead? |
| 2021-04-06 11:16:32 | <olligobber> | merijn, I am using reify to get the type |
| 2021-04-06 11:17:05 | <olligobber> | and I'm gonna use pprint instead of show |
| 2021-04-06 11:17:05 | <merijn> | olligobber: Why the show, though? |
| 2021-04-06 11:17:11 | <olligobber> | so it's a string |
| 2021-04-06 11:17:17 | <merijn> | What's gonna happen with that string? |
| 2021-04-06 11:17:19 | <olligobber> | |
| 2021-04-06 11:17:42 | <merijn> | So you're trying to print the string of the generated TH at compile time? |
| 2021-04-06 11:17:43 | × | xourt quits (d4c620ea@212-198-32-234.rev.numericable.fr) (Ping timeout: 240 seconds) |
| 2021-04-06 11:17:48 | <olligobber> | no |
| 2021-04-06 11:17:55 | <olligobber> | I'm trying to print the type of a function |
| 2021-04-06 11:18:04 | <olligobber> | at runtime |
| 2021-04-06 11:18:11 | × | stree quits (~stree@68.36.8.116) (Ping timeout: 240 seconds) |
| 2021-04-06 11:18:44 | <merijn> | olligobber: A polymorphic function, I assume? |
| 2021-04-06 11:18:50 | <olligobber> | yeah |
| 2021-04-06 11:18:55 | <merijn> | Else you could just use typeRep |
| 2021-04-06 11:19:16 | × | geowiesnot quits (~user@i15-les02-ix2-87-89-181-157.sfr.lns.abo.bbox.fr) (Ping timeout: 268 seconds) |
| 2021-04-06 11:19:18 | <olligobber> | oh, I don't just want the type of the thing |
| 2021-04-06 11:19:30 | <olligobber> | the type is TypedLambda t v, and I just want to print t |
| 2021-04-06 11:20:01 | <olligobber> | and it worked! wow |
| 2021-04-06 11:24:01 | <olligobber> | merijn, see: https://gist.github.com/olligobber/a8931ae1ed972e6d524063b079dcdefb |
| 2021-04-06 11:24:08 | <olligobber> | works fine |
| 2021-04-06 11:24:42 | <olligobber> | for one example |
| 2021-04-06 11:26:06 | <merijn> | olligobber: Careful an elder god doesn't fry your brain, staring into that abyss ;) |
| 2021-04-06 11:26:17 | <olligobber> | it's fine |
| 2021-04-06 11:26:46 | <merijn> | That's what all Lovecraft protoganists think before descending into gibbering madness ;) |
| 2021-04-06 11:27:26 | → | acidjnk_new joins (~acidjnk@p200300d0c72b95396118d8d56ee70ad6.dip0.t-ipconnect.de) |
| 2021-04-06 11:27:46 | <olligobber> | I chose this path when I started learning haskell |
| 2021-04-06 11:28:44 | <olligobber> | though better variable names from pprinting the types would be nice |
All times are in UTC.