Logs: freenode/#haskell
| 2020-09-30 19:18:49 | × | wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 264 seconds) |
| 2020-09-30 19:19:07 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 240 seconds) |
| 2020-09-30 19:19:11 | × | tbreslein quits (~tbreslein@2a02:8108:140:44f8::901) (Remote host closed the connection) |
| 2020-09-30 19:21:18 | × | Orbstheorem quits (~roosember@hellendaal.orbstheorem.ch) (Quit: WeeChat 2.3) |
| 2020-09-30 19:21:19 | × | texasmynsted quits (b9e53b1b@185.229.59.27) (Ping timeout: 245 seconds) |
| 2020-09-30 19:22:24 | <p0a> | Hello, I have this code: https://paste.tomsmeding.com/Y6afnL1R |
| 2020-09-30 19:22:25 | × | mu_ quits (~mu@unaffiliated/mu) (Read error: Connection reset by peer) |
| 2020-09-30 19:22:50 | → | mu_ joins (~mu@unaffiliated/mu) |
| 2020-09-30 19:22:51 | <p0a> | The error is that you can't have Eq, Show, Read be derived for File', I believe due to HKD. What can I do? |
| 2020-09-30 19:23:27 | hackage | poly 0.5.0.0 - Polynomials https://hackage.haskell.org/package/poly-0.5.0.0 (Bodigrim) |
| 2020-09-30 19:24:35 | → | xerox_ joins (~xerox@unaffiliated/xerox) |
| 2020-09-30 19:25:15 | <p0a> | I think I have to somehow use `deriving' with specific instances but I don't know how to do that |
| 2020-09-30 19:25:31 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-09-30 19:25:35 | <tomsmeding> | p0a: the issue is that to derive e.g. Eq for File' f, it is required that Eq (KHD f FilePath), etc. also holds |
| 2020-09-30 19:26:04 | <tomsmeding> | for simple cases ghc can automatically generate the necessary contexts in the generated instance, but apparently in this case it can't |
| 2020-09-30 19:26:20 | <p0a> | How can I provide the instances for File? That's the one I want |
| 2020-09-30 19:27:11 | <p0a> | if I add `deriving' after `type File = File' Identity' I get a parsing error |
| 2020-09-30 19:27:33 | <tomsmeding> | indeed, adding 'deriving' after a tye synonym declaration is invalid syntax |
| 2020-09-30 19:27:39 | <tomsmeding> | however, you can do it like this: |
| 2020-09-30 19:27:55 | × | alp quits (~alp@2a01:e0a:58b:4920:7484:254:28d2:c14c) (Ping timeout: 272 seconds) |
| 2020-09-30 19:28:15 | <tomsmeding> | https://paste.tomsmeding.com/okCA6gS4 |
| 2020-09-30 19:28:32 | × | AlterEgo- quits (~ladew@124-198-158-163.dynamic.caiway.nl) (Quit: Leaving) |
| 2020-09-30 19:28:32 | <tomsmeding> | StandaloneDeriving is to allow writing those, well, stand-alone 'deriving' statements |
| 2020-09-30 19:28:58 | <tomsmeding> | FlexibleInstances and TypeSynonymInstances is to be allowed to write an instance for a type synonym (i.e. File, as opposed to File') in the first place |
| 2020-09-30 19:29:18 | → | ahmr88 joins (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) |
| 2020-09-30 19:29:21 | <p0a> | heh thank you |
| 2020-09-30 19:29:26 | → | tinga joins (~tinga@5-168-208-80-pool.fiber.fcom.ch) |
| 2020-09-30 19:29:27 | <p0a> | that was tricky |
| 2020-09-30 19:29:48 | × | mnrmnaugh quits (~mnrmnaugh@unaffiliated/mnrmnaugh) (Remote host closed the connection) |
| 2020-09-30 19:29:49 | <tomsmeding> | (well really that's only TypeSynonymInstances; FlexibleInstances is then required because when expanding the File type synonym, the instance becomes Eq (File' Identity), and because that Identity is not a type variable, FlexibleInstances is needed) |
| 2020-09-30 19:29:53 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection) |
| 2020-09-30 19:30:10 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-09-30 19:30:22 | <tomsmeding> | generally when you want to derive instances that GHC doesn't do automatically, I try it as a standalone deriving statement |
| 2020-09-30 19:30:37 | <tomsmeding> | usually that will also not work (though sometimes it will), but then GHC tends to give better error messages |
| 2020-09-30 19:31:04 | <p0a> | hahah got it |
| 2020-09-30 19:31:06 | <tomsmeding> | in this case, if you just add StandaloneDeriving and write those stand-alone instances, it will correctly ask you to add the other two extensions |
| 2020-09-30 19:31:12 | <p0a> | you sort of have to squeeze it out of ghc |
| 2020-09-30 19:31:15 | <tomsmeding> | :p |
| 2020-09-30 19:31:54 | <p0a> | I am afraid I am not understanding the extensions very well but I will continue writing code for now |
| 2020-09-30 19:32:07 | <tomsmeding> | which one? |
| 2020-09-30 19:32:07 | <p0a> | that is, I do not understand their purpose |
| 2020-09-30 19:32:13 | × | mu_ quits (~mu@unaffiliated/mu) (Read error: Connection reset by peer) |
| 2020-09-30 19:32:23 | <p0a> | well let's start with TypeSynonymInstances |
| 2020-09-30 19:32:35 | <tomsmeding> | without any extensions, haskell only allows you to write an instance for a type of the form T a b c d |
| 2020-09-30 19:32:40 | <p0a> | Oh wait, that one you explained |
| 2020-09-30 19:32:42 | → | mu_ joins (~mu@unaffiliated/mu) |
| 2020-09-30 19:32:45 | <tomsmeding> | where T is a type name, and a b c d ... are type variables |
| 2020-09-30 19:32:47 | <p0a> | I think the cryptic one is FlexibleInstnaces |
| 2020-09-30 19:32:59 | <tomsmeding> | yeah |
| 2020-09-30 19:33:20 | <tomsmeding> | if T is a type synonym, it doesn't match the recipe so you need TypeSynonymInstances (which resolves the name first) |
| 2020-09-30 19:33:39 | <tomsmeding> | if a b c d, etc, are not type variables but explicitly instantiated to a particular type, then you need FlexibleInstances |
| 2020-09-30 19:33:58 | <tomsmeding> | for example, you can't write 'instance Show [MyCustomType]' directly |
| 2020-09-30 19:34:13 | <tomsmeding> | because that's, of course, really 'Show ([] MyCustomType)', and MyCustomType is not a type variable |
| 2020-09-30 19:34:23 | <p0a> | What is it instead? |
| 2020-09-30 19:34:28 | <tomsmeding> | well, a type :p |
| 2020-09-30 19:34:29 | <tomsmeding> | not a variable |
| 2020-09-30 19:34:31 | <p0a> | right, okay |
| 2020-09-30 19:34:39 | <tomsmeding> | you _can_ write 'instance Show [a]' because that is 'Show ([] a)' and 'a' _is_ a type variable |
| 2020-09-30 19:34:52 | <geekosaur> | except it'll overlap |
| 2020-09-30 19:34:58 | <tomsmeding> | basically, normally you can only create instances for _all_ polymorphic versions of a type |
| 2020-09-30 19:35:09 | <tomsmeding> | geekosaur: okay yes in this case for Show ([] ...) it will overlap |
| 2020-09-30 19:35:12 | <p0a> | I see, FlexibleInstances let's you exercise an incision |
| 2020-09-30 19:35:17 | <tomsmeding> | because there is already Show a => Show [a] |
| 2020-09-30 19:35:28 | <tomsmeding> | substitute some random other class for Show :p |
| 2020-09-30 19:35:35 | <tomsmeding> | p0a: kinda :) |
| 2020-09-30 19:36:01 | <tomsmeding> | once instance contexts start to get complex you might also need UndecidableInstances at some point |
| 2020-09-30 19:36:02 | <p0a> | Very nice, thank you :) that's an extension I commonly see |
| 2020-09-30 19:36:03 | → | madjestic joins (~madjestic@86-88-72-244.fixed.kpn.net) |
| 2020-09-30 19:36:20 | <tomsmeding> | though I don't know the precise rules for that one :) |
| 2020-09-30 19:36:29 | <p0a> | don't worry it's not on the menu right now |
| 2020-09-30 19:36:31 | <geekosaur> | "avoid" |
| 2020-09-30 19:36:35 | <p0a> | lol |
| 2020-09-30 19:36:52 | <tomsmeding> | well yeah, avoid most things that say "undecidable" |
| 2020-09-30 19:38:25 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2020-09-30 19:39:11 | × | ahmr88 quits (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) (Remote host closed the connection) |
| 2020-09-30 19:39:39 | → | borne joins (~fritjof@200116b864837e00537d5cc8226f9d9f.dip.versatel-1u1.de) |
| 2020-09-30 19:40:44 | <p0a> | If I want (Just 3) == 3 and Nothing == 3 to be True, how can I implement this? Say I have a :: Maybe Int and b :: Int, and wish to have the above comparisons |
| 2020-09-30 19:41:09 | <p0a> | I'm going to look into Control.Monad.Maybe |
| 2020-09-30 19:41:11 | <tomsmeding> | :t (==) |
| 2020-09-30 19:41:13 | <lambdabot> | Eq a => a -> a -> Bool |
| 2020-09-30 19:41:15 | <p0a> | Or Maybe Data.Maybe |
| 2020-09-30 19:41:23 | <tomsmeding> | Maybe Int does not unify with Int |
| 2020-09-30 19:41:30 | → | Orbstheorem joins (~roosember@hellendaal.orbstheorem.ch) |
| 2020-09-30 19:41:40 | → | kindaro joins (1f08d381@h31-8-211-129.dyn.bashtel.ru) |
| 2020-09-30 19:41:42 | <p0a> | Sure, it doesn't have to be with == , I'm just curious of neat source code to do that |
| 2020-09-30 19:41:49 | <{abby}> | > maybe 3 id (Just 3) |
| 2020-09-30 19:41:50 | <p0a> | my code would have if elses |
| 2020-09-30 19:41:51 | <lambdabot> | 3 |
| 2020-09-30 19:41:57 | <{abby}> | > maybe 3 id Nothing |
| 2020-09-30 19:42:00 | <lambdabot> | 3 |
| 2020-09-30 19:42:12 | × | mu_ quits (~mu@unaffiliated/mu) (Read error: Connection reset by peer) |
| 2020-09-30 19:42:18 | <tomsmeding> | > (fromMaybe 3 (Just 5), fromMaybe 3 Nothing) |
| 2020-09-30 19:42:20 | <lambdabot> | (5,3) |
| 2020-09-30 19:42:22 | <{abby}> | maybe default id = fromMaybe default, but I'm not sure if fromMaybe is in scope (import it from Data.Maybe) |
| 2020-09-30 19:42:27 | <tomsmeding> | that's what fromMaybe is for |
| 2020-09-30 19:42:42 | → | mu_ joins (~mu@unaffiliated/mu) |
| 2020-09-30 19:42:44 | <tomsmeding> | ah yes |
| 2020-09-30 19:43:10 | <tomsmeding> | p0a: surely it would be a case expression on the Maybe value, though, not an actual if-then-else? |
| 2020-09-30 19:43:29 | <p0a> | Right tomsmeding , but you can also use isJust and isNothing |
| 2020-09-30 19:43:30 | <{abby}> | tomsmeding: better safe than sorry :p I'm never sure what's in lambdabot's scope |
All times are in UTC.