Logs: freenode/#haskell
| 2020-10-05 17:22:34 | <ski> | @type lookup |
| 2020-10-05 17:22:35 | <lambdabot> | Eq a => a -> [(a, b)] -> Maybe b |
| 2020-10-05 17:22:36 | <ski> | @type M.lookup |
| 2020-10-05 17:22:37 | <lambdabot> | Ord k => k -> M.Map k a -> Maybe a |
| 2020-10-05 17:22:42 | <int-e> | . o O ( Lens s t a b ) |
| 2020-10-05 17:22:45 | <monochrom> | The greatest hypocrisy of people bragging about descriptive names is they go on to give you foo, bar, quux. |
| 2020-10-05 17:22:48 | <ski> | `k' here is reasonable, abbreviating "key" |
| 2020-10-05 17:23:00 | <zoom84> | back to my original question now |
| 2020-10-05 17:23:01 | <monochrom> | Proving that for generic things there is no such thing as descriptive names. |
| 2020-10-05 17:23:23 | <ski> | spelling out `key',`token',`stream',&c. all the time, might make some type signatures long enough, that they're harder to comprehend, though |
| 2020-10-05 17:23:27 | <int-e> | I'm really a fan of having the length (and hence "descriptiveness") of the name increase with its scope. |
| 2020-10-05 17:23:37 | → | borne joins (~fritjof@200116b86471bb007fe01feb1760d29e.dip.versatel-1u1.de) |
| 2020-10-05 17:23:41 | × | Lowl3v3l quits (~Lowl3v3l@dslb-090-186-188-115.090.186.pools.vodafone-ip.de) (Remote host closed the connection) |
| 2020-10-05 17:23:44 | <ski> | yes, that's a good guideline |
| 2020-10-05 17:24:01 | <zoom84> | instance Functor (MyEither a) where |
| 2020-10-05 17:24:01 | → | Lowl3v3l joins (~Lowl3v3l@dslb-090-186-188-115.090.186.pools.vodafone-ip.de) |
| 2020-10-05 17:24:06 | <zoom84> | fmap f (MyRight b) = MyRight (f b) |
| 2020-10-05 17:24:13 | <zoom84> | fmap f (MyLeft x) = MyLeft x |
| 2020-10-05 17:24:41 | <zoom84> | so for my fmap instances, the "a" in Either a b is not available. Only the "b" is available, correct? |
| 2020-10-05 17:25:11 | <monochrom> | Or you write "Either x" like I do, so a is available again. |
| 2020-10-05 17:25:12 | <dsal> | Correct. |
| 2020-10-05 17:25:18 | <ski> | zoom84 : which `Either a b' ? |
| 2020-10-05 17:25:27 | <zoom84> | good. how then does MyLeft x work then? Since MyLeft uses "a" |
| 2020-10-05 17:25:35 | <ski> | zoom84 : are you talking about the definition of the `data' type `Either' ? |
| 2020-10-05 17:25:40 | → | ericsagnes joins (~ericsagne@2405:6580:0:5100:e0:d1d9:7c60:99ac) |
| 2020-10-05 17:25:45 | <int-e> | :t fmap :: (b -> c) -> Either a b -> Either a c |
| 2020-10-05 17:25:47 | <lambdabot> | (b -> c) -> Either a b -> Either a c |
| 2020-10-05 17:25:50 | <dolio> | I think "correct" might be the wrong answer. |
| 2020-10-05 17:26:05 | <ski> | zoom84 : the `b' in `MyRight b' has nothing to do with the `b' in `MyEither a b' or `MyEither x b' |
| 2020-10-05 17:26:06 | <int-e> | That's the only possible Functor instance for Either. |
| 2020-10-05 17:26:20 | <zoom84> | I created my own MyEither. It's the same as Either. I did it so I can experiment trying to learn this aspect. Either vs MyEither interchangeable |
| 2020-10-05 17:26:23 | × | conal quits (~conal@64.71.133.70) (Quit: Computer has gone to sleep.) |
| 2020-10-05 17:27:17 | <ski> | zoom84 : yea, in `data MyEither a b = MyLeft a | MyRight b deriving Show', `a' and `b' are local names. they are not available outside this definition of `MyEither' |
| 2020-10-05 17:27:22 | → | mananamenos_ joins (~mananamen@vpn236-17.vpns.upv.es) |
| 2020-10-05 17:27:56 | <ski> | if you wanted to, you could define it as `data MyEither coffee tea = MyLeft coffee | MyRight tea deriving Show', and it would not affect other code at all |
| 2020-10-05 17:28:12 | → | bitmagie joins (~Thunderbi@200116b806da5f00187a54deb389527f.dip.versatel-1u1.de) |
| 2020-10-05 17:28:16 | <int-e> | zoom84: note that you had to write `instance Functor (MyEither a) where`, with only the last type parameter left out; that's all Haskell can do. |
| 2020-10-05 17:28:51 | <int-e> | (You could use a different variable name for that `a` though.) |
| 2020-10-05 17:29:21 | <ski> | zoom84 : it's just a convention to start naming the parameters `a',`b',`c',..., unless there's some particular significance (rôle) one may want to hint, like `k' for "key", `t' for "token", `f' for "functor", &c. |
| 2020-10-05 17:29:29 | <zoom84> | yeah, convention still tripping me up |
| 2020-10-05 17:29:35 | <int-e> | . o O ( instance Functor (Either idontcarewhatthisisaslongasitsneitheranorb) where ... ) |
| 2020-10-05 17:29:44 | <dsal> | Oh, is it the variable name that is confusing? |
| 2020-10-05 17:29:48 | × | mirrorbird quits (~psutcliff@2a00:801:2d5:9d73:ff00:6553:d451:a276) (Ping timeout: 244 seconds) |
| 2020-10-05 17:30:06 | <monochrom> | I think it is the notion of dummy variables. |
| 2020-10-05 17:30:10 | <zoom84> | rewriting my sample now with totally different names |
| 2020-10-05 17:30:25 | × | bitmagie quits (~Thunderbi@200116b806da5f00187a54deb389527f.dip.versatel-1u1.de) (Client Quit) |
| 2020-10-05 17:30:27 | × | alp quits (~alp@2a01:e0a:58b:4920:79a7:73ea:36f8:a1c9) (Ping timeout: 240 seconds) |
| 2020-10-05 17:30:28 | <zoom84> | to make it obvious...i'll see if it clicks then |
| 2020-10-05 17:30:51 | × | mananamenos quits (~mananamen@84.122.202.215.dyn.user.ono.com) (Ping timeout: 258 seconds) |
| 2020-10-05 17:30:57 | <ski> | zoom84 : it's also quite common, if you have say type variables `a',`b',`c' in a type signature, to also name corresponding values, in the definition, `a',`b',`c'. but one could instead name these `x',`y',`z' (so that we get `x :: a',`y :: b',`z :: c', which looks less confusing than `a :: a',`b :: b',`c :: c') |
| 2020-10-05 17:31:10 | → | Buntspecht joins (~user@unaffiliated/siracusa) |
| 2020-10-05 17:31:42 | <ski> | (or, if you have a list of values of type `a', it could commonly be called `as', so that you have `as :: [a]'. but you could instead call it `xs', so that you have `xs :: [a]') |
| 2020-10-05 17:31:46 | <zoom84> | data MyEither dog cat = MyLeft dog | MyRight cat deriving(Show) |
| 2020-10-05 17:31:53 | <zoom84> | instance Functor (MyEither doodad) where |
| 2020-10-05 17:31:58 | <zoom84> | fmap f (MyRight x) = MyRight (f x) |
| 2020-10-05 17:32:14 | <zoom84> | fmap f (MyLeft x) = MyLeft x |
| 2020-10-05 17:32:23 | × | mav1 quits (~mav@i59F4E23A.versanet.de) (Ping timeout: 258 seconds) |
| 2020-10-05 17:32:25 | <ski> | zoom84 : did you try my `InstanceSigs' suggestion from above ? |
| 2020-10-05 17:32:56 | <ski> | try adding the line |
| 2020-10-05 17:32:57 | <ski> | {-# LANGUAGE InstanceSigs #-} |
| 2020-10-05 17:33:04 | <ski> | at the top of your source file |
| 2020-10-05 17:33:14 | <zoom84> | if I do the following in ghci: fmap (*2) (MyLeft 10) |
| 2020-10-05 17:33:15 | <monochrom> | Koodos for writing code to test your understanding |
| 2020-10-05 17:33:24 | geekosaur | hopes there was some indentation there, also |
| 2020-10-05 17:33:39 | <ski> | then, just above the definition of `fmap' in your instance, you can write the type signature for `fmap' that you expect, for `MyEither' |
| 2020-10-05 17:33:42 | → | is_null joins (~jpic@pdpc/supporter/professional/is-null) |
| 2020-10-05 17:34:03 | <ski> | zoom84 : try `fmap (* 2) (MyLeft 10) :: MyEither Integer Bool' |
| 2020-10-05 17:34:34 | <zoom84> | my original statement works |
| 2020-10-05 17:34:42 | → | phaul joins (~phaul@ruby/staff/phaul) |
| 2020-10-05 17:34:52 | <zoom84> | i'm trying to understand what that fmap instance actually receives |
| 2020-10-05 17:34:54 | <ski> | hm, actually, say `fmap (* 2) (MyLeft 10) :: MyEither Integer Double' |
| 2020-10-05 17:35:02 | <monochrom> | ski, there is ExtendedDefaulting to default to MyEither Integer () :) |
| 2020-10-05 17:35:17 | <ski> | yea, i just recalled :) |
| 2020-10-05 17:35:29 | → | fog joins (c1b057e2@gateway/web/cgi-irc/kiwiirc.com/ip.193.176.87.226) |
| 2020-10-05 17:36:05 | <fog> | its not my fault! its election season - all the lobbying efforts and competing partisan spending distorts the fabric of reality |
| 2020-10-05 17:36:50 | ChanServ | sets mode +o monochrom |
| 2020-10-05 17:36:55 | monochrom | sets mode +b *!*@gateway/web/cgi-irc/kiwiirc.com/ip.193.176.87.226 |
| 2020-10-05 17:36:55 | fog | is kicked by monochrom (fog) |
| 2020-10-05 17:37:34 | → | Guest_57 joins (590fec7f@x590fec7f.dyn.telefonica.de) |
| 2020-10-05 17:37:55 | <zoom84> | does this implicit type signature look about right: (a -> b) -> MyEither doodad foobar -> MyEither a b |
| 2020-10-05 17:38:05 | <ski> | no |
| 2020-10-05 17:38:17 | <ski> | try writing |
| 2020-10-05 17:38:22 | <ski> | fmap :: (a -> b) -> MyEither doodad foobar -> MyEither a b |
| 2020-10-05 17:38:28 | hackage | fused-effects-mwc-random 0.1.0.0 - High-quality random number generation as an effect. https://hackage.haskell.org/package/fused-effects-mwc-random-0.1.0.0 (patrick_thomson) |
| 2020-10-05 17:38:29 | <ski> | above your definition, and see how it complains |
| 2020-10-05 17:38:37 | <zoom84> | not writing the signaturte |
| 2020-10-05 17:38:47 | <zoom84> | trying to impute the equivalent |
| 2020-10-05 17:38:58 | <ski> | you can check your understanding, by writing the signature that you expect |
| 2020-10-05 17:39:12 | × | John20 quits (~John@82.46.59.122) (Ping timeout: 256 seconds) |
| 2020-10-05 17:39:26 | <ski> | where did `doodad' and `foobar' come from ? |
| 2020-10-05 17:39:32 | <ski> | where did `a' and `b' come from ? |
| 2020-10-05 17:39:55 | × | kritzefitz quits (~kritzefit@212.86.56.80) (Ping timeout: 240 seconds) |
| 2020-10-05 17:39:57 | <zoom84> | where i can specify that signature? |
| 2020-10-05 17:40:07 | <ski> | just above the definition of `fmap' |
| 2020-10-05 17:40:40 | <zoom84> | The type signature for ‘fmap’ lacks an accompanying binding (The type signature must be given where ‘fmap’ is declared) |795 | fmap :: (a -> b) -> MyEither doodad foobar -> MyEither a b |
| 2020-10-05 17:41:10 | <zoom84> | fmap is in a library source file. you're saying i should put it there? |
| 2020-10-05 17:41:34 | geekosaur | again points to indentation |
| 2020-10-05 17:42:08 | × | idhugo quits (~idhugo@563472ae.rev.stofanet.dk) (Ping timeout: 260 seconds) |
| 2020-10-05 17:42:18 | <MarcelineVQ> | This requires InstanceSigs |
| 2020-10-05 17:42:32 | <ski> | (as was already mentioned, twice or thrice :) |
All times are in UTC.