Logs: freenode/#haskell
| 2020-09-30 19:43:40 | <tomsmeding> | {abby}: fair :p |
| 2020-09-30 19:43:51 | <kindaro> | In Template Haskell, how can I convert an `Exp` to a `Pat`? I have a `Type` and I want to pattern match on its literal name as given by `Type.Reflection.tyConName`. |
| 2020-09-30 19:44:01 | <tomsmeding> | p0a: isJust and fromJust? while there are legitimate use cases for fromJust, think thrice when using it |
| 2020-09-30 19:44:12 | <p0a> | (x == \x -> fromMaybe x y) is then what I'd do I think |
| 2020-09-30 19:44:19 | <p0a> | thank you |
| 2020-09-30 19:44:21 | <tomsmeding> | because usually you're better off with a case expression or an existing combinator |
| 2020-09-30 19:44:23 | <kindaro> | So, I can construct an `Exp` with a quasi quote, but it seems I cannot construct a `Pat`. |
| 2020-09-30 19:44:32 | <tomsmeding> | less partiality more better |
| 2020-09-30 19:44:41 | <p0a> | right, that is true |
| 2020-09-30 19:45:12 | <kindaro> | For example, this would not work: `getTypeNameLiteral subject = (tyConName ∘ typeRepTyCon) (typeRep @ $(return subject))` |
| 2020-09-30 19:45:54 | <kindaro> | This compiles but gives me a `Q Exp`: `getTypeNameLiteral subject = [|(tyConName ∘ typeRepTyCon) (typeRep @ $(return subject))|]` |
| 2020-09-30 19:46:09 | × | filwisher quits (~filwisher@cpc76738-dals23-2-0-cust186.20-2.cable.virginm.net) (Ping timeout: 260 seconds) |
| 2020-09-30 19:46:27 | <kindaro> | This does not compile: `getTypeNameLiteral subject = [p|(tyConName ∘ typeRepTyCon) (typeRep @ $(return subject))|]` |
| 2020-09-30 19:46:36 | <tomsmeding> | what kind of pattern would you want it to be |
| 2020-09-30 19:46:47 | <tomsmeding> | string? data constructor? |
| 2020-09-30 19:46:58 | <tomsmeding> | can't you create the Pat value yourself |
| 2020-09-30 19:47:01 | <tomsmeding> | https://hackage.haskell.org/package/template-haskell-2.16.0.0/docs/Language-Haskell-TH.html |
| 2020-09-30 19:47:43 | <kindaro> | For `Type` = `(ConT GHC.Types.Int)`, I would like `"Int"`, and so on. |
| 2020-09-30 19:48:19 | <kindaro> | I cannot create a `Pat` value because I have no idea what string `tyConName` would produce. |
| 2020-09-30 19:48:32 | <kindaro> | I have to first run `tyConName` somehow. |
| 2020-09-30 19:49:04 | <tomsmeding> | oh your problem is to get the TyCon to pass to tyConName? |
| 2020-09-30 19:49:10 | <tomsmeding> | from what do you want to get it |
| 2020-09-30 19:49:18 | <tomsmeding> | a value of that type? |
| 2020-09-30 19:49:19 | <kindaro> | From `Type`. |
| 2020-09-30 19:49:50 | <kindaro> | This `Type`: https://hackage.haskell.org/package/template-haskell-2.16.0.0/docs/Language-Haskell-TH.html#t:Type |
| 2020-09-30 19:50:01 | × | ADG1089 quits (uid455466@gateway/web/irccloud.com/x-wfsqzgfoscwuqfvc) (Quit: Connection closed for inactivity) |
| 2020-09-30 19:50:05 | × | JoelMcCracken[m] quits (joelmccrac@gateway/shell/matrix.org/x-fkrjmkjfhjvsypdi) (Quit: authenticating) |
| 2020-09-30 19:50:12 | → | JoelMcCracken[m] joins (joelmccrac@gateway/shell/matrix.org/x-nmxpzgkyreszwsoo) |
| 2020-09-30 19:50:15 | <kindaro> | So, I first have to convert this `Type` to an actual expression, at which point it becomes incompatible with `Pat`. |
| 2020-09-30 19:50:25 | <tomsmeding> | but, a type can have many constructors, right? |
| 2020-09-30 19:50:32 | <tomsmeding> | data A = A | B |
| 2020-09-30 19:50:39 | <kindaro> | It has one type constructor. |
| 2020-09-30 19:50:42 | <tomsmeding> | if the Type is A, do you want the TyCon for A or for B? |
| 2020-09-30 19:50:43 | <tomsmeding> | ah |
| 2020-09-30 19:50:43 | <kindaro> | In your case `A`. |
| 2020-09-30 19:50:50 | → | nobody239419341 joins (5e7be5a0@94.123.229.160) |
| 2020-09-30 19:51:01 | <tomsmeding> | can't you use generics |
| 2020-09-30 19:51:18 | <kindaro> | Like how? |
| 2020-09-30 19:51:54 | → | conal joins (~conal@64.71.133.70) |
| 2020-09-30 19:51:57 | <kindaro> | As you may remember, my problem can be put as constructing a large case expression. |
| 2020-09-30 19:52:06 | <tomsmeding> | right |
| 2020-09-30 19:52:13 | <kindaro> | The way to do that is via Template Haskell. |
| 2020-09-30 19:52:13 | × | mu_ quits (~mu@unaffiliated/mu) (Read error: Connection reset by peer) |
| 2020-09-30 19:52:16 | <aldessa> | by the way for my earlier problem, the solution was 'stack ls --dependencies --no-include-base --license' to see all the licenses |
| 2020-09-30 19:52:27 | hackage | deriving-compat 0.5.10 - Backports of GHC deriving extensions https://hackage.haskell.org/package/deriving-compat-0.5.10 (ryanglscott) |
| 2020-09-30 19:52:29 | × | ransom quits (~c4264035@undergraduate-jvossen-9690.mines.edu) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2020-09-30 19:52:41 | → | mu_ joins (~mu@unaffiliated/mu) |
| 2020-09-30 19:52:44 | × | mirrorbird quits (~psutcliff@2a00:801:3fb:53b9:b09b:cd4e:4e4a:44a9) (Ping timeout: 244 seconds) |
| 2020-09-30 19:52:49 | <kindaro> | I made some progress, but it is unclear how I can associate a literal pattern with a `Type`. |
| 2020-09-30 19:52:51 | <nobody239419341> | hello can someone help me understand this function signrature `palindrome = reverse >>= (==)` I'm beginner to haskell |
| 2020-09-30 19:53:45 | <Cheery> | :t reverse >>= (==) |
| 2020-09-30 19:53:45 | <sm[m]> | aldessa: stack ls dependencies --no-include-base --license ... very cool, thanks |
| 2020-09-30 19:53:46 | <lambdabot> | Eq a => [a] -> Bool |
| 2020-09-30 19:53:50 | <tomsmeding> | kindaro: I know how to write a function 'magic :: Generic a => String' that produces the name of the first type constructor of 'a'; would that be sufficient for you? |
| 2020-09-30 19:53:53 | <monochrom> | It is not for beginners. Please don't worry about that one. Please learn and play with basic examples first. |
| 2020-09-30 19:54:09 | <p0a> | nobody239419341: I believe that is not a signature. I think signatures refer to the types after :: |
| 2020-09-30 19:54:12 | <monochrom> | Whoever showed you "reverse >>= (==)" did not respect that you are a beginner. |
| 2020-09-30 19:54:13 | <tomsmeding> | kindaro: I'm not familiar enough with TH to know whether generics play nicely with it |
| 2020-09-30 19:54:44 | <nobody239419341> | I was self learning from https://wiki.haskell.org/99_questions/Solutions/6 here and would like to understand that solution |
| 2020-09-30 19:54:46 | <kindaro> | I expect that they do not. |
| 2020-09-30 19:54:54 | <nobody239419341> | I wrote first solution myself without looking to the solutions page |
| 2020-09-30 19:56:04 | <nobody239419341> | I know how would I look to the function signatures by ` :t ` in ghci |
| 2020-09-30 19:56:06 | <Cheery> | :t (>>=) reverse |
| 2020-09-30 19:56:08 | <lambdabot> | ([a] -> [a] -> b) -> [a] -> b |
| 2020-09-30 19:56:14 | <Cheery> | :t (==) |
| 2020-09-30 19:56:16 | <lambdabot> | Eq a => a -> a -> Bool |
| 2020-09-30 19:56:58 | <tomsmeding> | kindaro: 'tyConName (typeRepTyCon (typeRep @T))' is of type String |
| 2020-09-30 19:57:01 | sm[m] | discovers a few weirdo packages using BSD-2 (megaparsec & text) |
| 2020-09-30 19:57:09 | <tomsmeding> | not sure where Exp comes into the discussion |
| 2020-09-30 19:57:32 | <tomsmeding> | also I now realise that you're talking about the _type_ constructor, not a _data_ constructor :p |
| 2020-09-30 19:58:16 | × | ddellacosta quits (~dd@86.106.121.168) (Quit: WeeChat 2.8) |
| 2020-09-30 19:58:52 | tomsmeding | is surprised about the amount of reflection that ghc gives you with Type.Reflection, Data.Typeable and templatehaskell |
| 2020-09-30 19:59:14 | <kindaro> | nobody239419341 This is some advanced Haskell, I have been doing it for some years but it took me effort to understand how your function works. You may wish to consult the Monad instance for functions. https://hackage.haskell.org/package/base-4.14.0.0/docs/src/GHC.Base.html#line-979 |
| 2020-09-30 19:59:16 | <Cheery> | tomsmeding: any short introduction to Type Reflection you'd recommend? |
| 2020-09-30 19:59:28 | <Cheery> | or data typeable, those sound interesting. |
| 2020-09-30 20:00:26 | × | Quarl quits (~Quarl@94.191.138.174.mobile.tre.se) (Read error: Connection reset by peer) |
| 2020-09-30 20:00:30 | <tomsmeding> | Cheery: I learned about the existence of Type.Reflection when kindaro mentioned it |
| 2020-09-30 20:00:37 | <tomsmeding> | I'm afraid I'm not the right person to ask :p |
| 2020-09-30 20:00:39 | <Cheery> | nobody239419341: that implementation for checking palindrome is vicious. |
| 2020-09-30 20:00:41 | <nobody239419341> | kindaro thank you I will look to it |
| 2020-09-30 20:00:43 | <kindaro> | nobody239419341 As you may see, it does exactly what you need it to do. _«Why»_ is another question. It is fair to say that I never ever used the monad instance for functions. |
| 2020-09-30 20:01:01 | <p0a> | Oh so that's what it is using. Wow, tricky |
| 2020-09-30 20:01:37 | <Cheery> | functions make a valid monad with their last argument.. it's a bit difficult to understand but it's valid. |
| 2020-09-30 20:01:38 | <kindaro> | Seeing that `Reader` is really a function, this may give some intuition. |
| 2020-09-30 20:01:45 | <sm[m]> | ...and one weirdo using ISC (glguy :). Interesting, I didn't know about ISC |
| 2020-09-30 20:01:58 | hackage | linear 1.21.2 - Linear Algebra https://hackage.haskell.org/package/linear-1.21.2 (ryanglscott) |
| 2020-09-30 20:02:09 | <sm[m]> | https://www.gnu.org/licenses/license-list.en.html#ISC |
| 2020-09-30 20:02:10 | × | mu_ quits (~mu@unaffiliated/mu) (Read error: Connection reset by peer) |
| 2020-09-30 20:02:19 | <Cheery> | nobody239419341: [a] -> [a] is the type signature for reverse. |
| 2020-09-30 20:02:31 | <p0a> | Cheery: I think this explains some of it? https://mjoldfield.com/atelier/2014/07/monads-fn.html |
| 2020-09-30 20:02:33 | <nobody239419341> | yes |
| 2020-09-30 20:02:34 | <p0a> | Or am I wrong? |
| 2020-09-30 20:02:42 | → | mu_ joins (~mu@unaffiliated/mu) |
| 2020-09-30 20:02:52 | <tomsmeding> | sm[m]: what about https://hackage.haskell.org/package/dependent-map |
| 2020-09-30 20:02:58 | × | eyenx quits (~eyenxeyen@unaffiliated/eye/x-1653358) (Quit: killed) |
| 2020-09-30 20:03:05 | → | xcmw joins (~textual@dyn-72-33-0-89.uwnet.wisc.edu) |
| 2020-09-30 20:03:07 | <Cheery> | nobody239419341: now imagine that's something like F [a] where F x = [a] -> x |
| 2020-09-30 20:03:50 | <nobody239419341> | what does it mean to apply the infix operator `->` for function definition |
| 2020-09-30 20:04:04 | → | ddellacosta joins (~dd@86.106.121.168) |
| 2020-09-30 20:04:26 | <kindaro> | tomsmeding, so the story goes: I get the list of `Type` values by examining `reifyInstances`. Now I must use `tyConName` on the corresponding types. But this correspondence is not trivial to establish. |
All times are in UTC.