Logs: freenode/#haskell
| 2020-09-17 18:04:57 | <dumptruckman> | s/define/ |
| 2020-09-17 18:04:59 | <ski> | yes, that's how instances work |
| 2020-09-17 18:05:05 | <dumptruckman> | well yeah.. |
| 2020-09-17 18:05:07 | <tomsmeding> | well, like, there's generics |
| 2020-09-17 18:05:31 | <dumptruckman> | but like, i don't have to implement anything to use Show for most stuff |
| 2020-09-17 18:05:42 | <tomsmeding> | because Show is hard-wired :) |
| 2020-09-17 18:05:43 | <dumptruckman> | so it has some kind of default implementation that "just works"? |
| 2020-09-17 18:05:43 | <ski> | because `Show' can be derived |
| 2020-09-17 18:05:55 | <tomsmeding> | you can use generics to do what you want, I think |
| 2020-09-17 18:06:02 | <ski> | (and, usually, should be derived) |
| 2020-09-17 18:06:03 | <tomsmeding> | but it's not very pretty |
| 2020-09-17 18:06:04 | <geekosaur> | but you must derive it for it to be there |
| 2020-09-17 18:06:14 | <dumptruckman> | right |
| 2020-09-17 18:06:28 | <dumptruckman> | so i guess it's not an instance of the typeclass if i simply derive that typeclass |
| 2020-09-17 18:06:55 | <dumptruckman> | so i suppose i'm wondering if there's a way to do this without making my data types an instance of it |
| 2020-09-17 18:07:05 | <monochrom> | Rather, "deriving" is not for arbitrary classes of your own design. |
| 2020-09-17 18:07:25 | <tomsmeding> | except for obscure ghc extensions mumble mumble |
| 2020-09-17 18:07:40 | → | eric joins (~eric@2804:431:c7d4:b75:69f1:6cfd:8841:8fad) |
| 2020-09-17 18:07:54 | <tomsmeding> | but, yes, in vanilla haskell, "deriving" is only for built-in things |
| 2020-09-17 18:08:42 | <tomsmeding> | dumptruckman: alternative track: what if you define a type 'data CachedShow a = CachedShow String a' |
| 2020-09-17 18:08:44 | <dumptruckman> | ahh |
| 2020-09-17 18:08:52 | → | nyd joins (~nyd@unaffiliated/elysian) |
| 2020-09-17 18:09:17 | <tomsmeding> | and then define 'data Something a = Something (CachedShow a)' |
| 2020-09-17 18:09:20 | <dumptruckman> | ahhh |
| 2020-09-17 18:09:23 | <dumptruckman> | that's a good idea |
| 2020-09-17 18:09:25 | <tomsmeding> | where that 'a' is whatever you want of course |
| 2020-09-17 18:09:30 | <sm[m]> | I got an SDL app working in GHCI by using -fno-ghci-sandbox per https://stackoverflow.com/questions/61842338/creating-an-sdl2-window-inside-ghci . But I'm having trouble getting rid of the window when the app exits. destroyWindow having no effect. Has anyone got this working ? |
| 2020-09-17 18:09:49 | <tomsmeding> | then if you say 'instance Show (CachedShow a) where show (CachedShow s _) = s' |
| 2020-09-17 18:09:57 | <tomsmeding> | and just use 'deriving (Show)' on Something |
| 2020-09-17 18:10:14 | <tomsmeding> | then you get 'Something [whatever that string has]', which is not exactly what you asked, but it's close |
| 2020-09-17 18:10:31 | <tomsmeding> | downside is that now there's a CachedShow constructor in between the Something constructor and the contained data |
| 2020-09-17 18:10:41 | <dumptruckman> | or i could simply do: `data Name = Name String` `name :: Name -> String` ` name (Name s) = s` `data Something = Something name a b c` |
| 2020-09-17 18:10:43 | <dumptruckman> | i think |
| 2020-09-17 18:10:43 | <tomsmeding> | but if you're okay with that, this is a very vanilla way of sort-of getting that :) |
| 2020-09-17 18:11:09 | <tomsmeding> | well 'Something Name a b c', not 'Something name a b c', but yes |
| 2020-09-17 18:11:17 | <dumptruckman> | yes |
| 2020-09-17 18:11:20 | <dumptruckman> | that's what i meant |
| 2020-09-17 18:11:22 | <tomsmeding> | but then you still need to implement Show for Something yourself |
| 2020-09-17 18:11:22 | <dumptruckman> | oh but wait |
| 2020-09-17 18:11:29 | <tomsmeding> | so you haven't won anything |
| 2020-09-17 18:11:32 | <dumptruckman> | and i'd still have to implement name |
| 2020-09-17 18:11:40 | <dumptruckman> | name :: Show -> String |
| 2020-09-17 18:11:48 | <dumptruckman> | er, name :: Something -> String |
| 2020-09-17 18:11:49 | <ski> | tomsmeding : that would be bad, imho :) |
| 2020-09-17 18:11:55 | → | fendor joins (~fendor@77.119.129.27.wireless.dyn.drei.com) |
| 2020-09-17 18:11:59 | → | Gigabitten joins (~Somn@ip-99-203-18-60.pools.cgn.spcsdns.net) |
| 2020-09-17 18:12:01 | <tomsmeding> | the point of my solution, with wrapping the rest of the Something contents _inside_ that Name, you can just 'deriving (Show)' and it works |
| 2020-09-17 18:12:18 | <tomsmeding> | ski: yes you haven't won anything and you've made it more complicated :p |
| 2020-09-17 18:12:25 | <tomsmeding> | or are you referring to my CachedShow thing |
| 2020-09-17 18:12:26 | <ski> | (imho, that `Show' instance is incorrect) |
| 2020-09-17 18:12:27 | <ski> | yes |
| 2020-09-17 18:12:29 | × | eric quits (~eric@2804:431:c7d4:b75:69f1:6cfd:8841:8fad) (Ping timeout: 272 seconds) |
| 2020-09-17 18:12:32 | <tomsmeding> | sure |
| 2020-09-17 18:12:41 | × | z0 quits (~z0@bl15-162-186.dsl.telepac.pt) (Quit: leaving) |
| 2020-09-17 18:12:43 | <tomsmeding> | was just trying to satisfy dumptruckman's wishes :p |
| 2020-09-17 18:12:53 | <tomsmeding> | but I guess yes, perhaps this shouldn't be Show, dumptruckman |
| 2020-09-17 18:12:56 | <ski> | well .. they didn't seem to ask for `name' to be related to `show' |
| 2020-09-17 18:13:01 | × | Gigabitten quits (~Somn@ip-99-203-18-60.pools.cgn.spcsdns.net) (Client Quit) |
| 2020-09-17 18:13:02 | <tomsmeding> | OW |
| 2020-09-17 18:13:10 | <tomsmeding> | my bad |
| 2020-09-17 18:13:27 | <tomsmeding> | okay fair point gimme 1min |
| 2020-09-17 18:14:47 | <dumptruckman> | yeah, i just have a bunch of different data types that all have a name |
| 2020-09-17 18:14:57 | <dumptruckman> | and instead of having a separate name function for each i'd like to just use name |
| 2020-09-17 18:15:02 | × | gestone quits (~gestone@c-73-97-137-216.hsd1.wa.comcast.net) (Ping timeout: 260 seconds) |
| 2020-09-17 18:15:37 | <tomsmeding> | okay so am I allowed to cheat and use GeneralizedNewtypeDeriving |
| 2020-09-17 18:15:45 | <monochrom> | Do you really have an algorithm that cannot be written if every type has a separate name function? |
| 2020-09-17 18:15:46 | → | Kaiepi joins (~Kaiepi@nwcsnbsc03w-47-55-157-9.dhcp-dynamic.fibreop.nb.bellaliant.net) |
| 2020-09-17 18:15:54 | <dumptruckman> | no |
| 2020-09-17 18:16:00 | <dumptruckman> | it's more of a clarity thing i guess |
| 2020-09-17 18:16:00 | <monochrom> | Then YAGNI |
| 2020-09-17 18:16:16 | → | livvy joins (~livvy@gateway/tor-sasl/livvy) |
| 2020-09-17 18:16:28 | <monochrom> | "clarity by overloading names" is in perpetual controversy. |
| 2020-09-17 18:16:33 | <dumptruckman> | so i don't have to do `worldName world` `playerName player` `sharableName sharable` etc |
| 2020-09-17 18:16:54 | <dumptruckman> | it maybe be a case of YAGNI but at the same time, i'd love to learn how to do this |
| 2020-09-17 18:17:08 | <tomsmeding> | dumptruckman: implementation of my wacked idea: https://paste.tomsmeding.com/bSSsxieh |
| 2020-09-17 18:17:20 | <tomsmeding> | 1. the newtype is crucial, 2. you need that HasName in between |
| 2020-09-17 18:17:36 | <tomsmeding> | if you don't want the HasName, you need to use generics |
| 2020-09-17 18:17:43 | <tomsmeding> | or not do this at all :) |
| 2020-09-17 18:17:46 | <geekosaur> | this sounds like the kind of record field problem lens packages are designed for |
| 2020-09-17 18:17:53 | → | frdg joins (~user@pool-71-184-143-249.bstnma.fios.verizon.net) |
| 2020-09-17 18:17:58 | <ski> | dumptruckman : "i just have a bunch of different data types that all have a name","and instead of having a separate name function for each i'd like to just use name" -- that's what i figured possibly was the case :) |
| 2020-09-17 18:18:24 | <dumptruckman> | sorry, i should've just said that but it wasn't immediately obvious to myself |
| 2020-09-17 18:18:24 | → | ahmr88 joins (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) |
| 2020-09-17 18:18:37 | <dumptruckman> | tomsmeding: only thing is the tuple feels weird |
| 2020-09-17 18:18:40 | <monochrom> | For learning purpose, just handwrite every instance. You said it, "learning". |
| 2020-09-17 18:18:48 | <tomsmeding> | yeah the tuple is "whatever data you want there" |
| 2020-09-17 18:18:58 | <tomsmeding> | had to put something :) |
| 2020-09-17 18:18:59 | <ski> | dumptruckman : so .. since it seems you don't want to write overloaded polymorphic operations wrt this type class, i'd suggest that it's probably better to not make such a type class |
| 2020-09-17 18:19:06 | <tomsmeding> | RT monochrom |
| 2020-09-17 18:19:13 | <monochrom> | For thinking purpose, http://www.cs.utoronto.ca/~trebla/CSCC24-2020-Summer/05-haskell-types-2.html#why |
| 2020-09-17 18:19:19 | × | pingiun quits (~pingiun@ip-213-124-184-182.ip.prioritytelecom.net) (Quit: Textual IRC Client: www.textualapp.com) |
| 2020-09-17 18:19:28 | <dumptruckman> | i'd still like to be able to use the format like `Player { playerName :: String }` |
| 2020-09-17 18:19:49 | <dumptruckman> | i tried to do it where each type was like `Player { name :: String }` but it yelled at me |
| 2020-09-17 18:20:24 | <dumptruckman> | monochrom: haha nice |
| 2020-09-17 18:21:32 | <ski> | monochrom : the law thing is a good point to bring up. perhaps you'd want to add the "have overloaded polymorphic operations defined in terms of methods" point to that, as well ? |
| 2020-09-17 18:21:53 | <monochrom> | That's "can be used to build useful general algorithms" |
| 2020-09-17 18:21:58 | <ski> | tomsmeding : "RT" ? |
| 2020-09-17 18:22:01 | <tomsmeding> | retweet |
| 2020-09-17 18:22:08 | <ski> | mhm |
| 2020-09-17 18:22:12 | <dolio> | I don't see what's wrong with using type classes to overload something like this. |
All times are in UTC.