Logs: freenode/#haskell
| 2020-09-20 12:08:01 | × | rprije quits (~rprije@27.143.220.203.dial.dynamic.acc01-myal-dub.comindico.com.au) (Ping timeout: 258 seconds) |
| 2020-09-20 12:08:03 | × | p-core quits (~Thunderbi@koleje-wifi-0046.koleje.cuni.cz) (Quit: p-core) |
| 2020-09-20 12:08:18 | <edwardk> | if that data type didn't type check this wouldn't be so infuriating |
| 2020-09-20 12:08:23 | <edwardk> | because i'd know it was impossible |
| 2020-09-20 12:08:25 | → | p-core joins (~Thunderbi@koleje-wifi-0046.koleje.cuni.cz) |
| 2020-09-20 12:08:27 | <gpvs> | ski: `class Show type_self => Animal type_self where say :: AWord type_word => type_self -> [type_word]' I got error trying to compile it. It's in https://dpaste.com/EG5RM5HXY . Did I missed some required extensions? |
| 2020-09-20 12:08:29 | <edwardk> | but that is just hunky dory |
| 2020-09-20 12:08:45 | <Cale> | edwardk: hmm, think I'll have to fire up ghci here... :) |
| 2020-09-20 12:10:15 | <gpvs> | ski: this `class (Show type_self, AWord type_word) => Animal type_self where say :: type_self -> [type_word]' got me compile error too. https://dpaste.com/FTAG9S4MQ |
| 2020-09-20 12:10:16 | <ski> | gpvs : no, your `say' implementation doesn't satisfy that type signature |
| 2020-09-20 12:10:34 | <ski> | (the `say :: AWord type_word => type_self -> [type_word]' one, i mean) |
| 2020-09-20 12:11:03 | <Cale> | gpvs: You need another parameter on the class there |
| 2020-09-20 12:11:29 | <Cale> | gpvs: class (Show s, AWord w) => Animal s w where say :: [s] -> [w] |
| 2020-09-20 12:11:30 | <ski> | gpvs : oh, sorry. the middle alternative should have been `class (Show type_self, AWord type_word) => Animal type_self type_word where say :: type_self -> [type_word]' .. iow MPTC |
| 2020-09-20 12:11:44 | <ski> | Cale : no list input |
| 2020-09-20 12:11:45 | → | heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) |
| 2020-09-20 12:12:07 | <Cale> | oh |
| 2020-09-20 12:12:08 | × | p-core quits (~Thunderbi@koleje-wifi-0046.koleje.cuni.cz) (Client Quit) |
| 2020-09-20 12:12:09 | <Cale> | okay |
| 2020-09-20 12:12:17 | <Cale> | yeah, just s -> [w] in that case |
| 2020-09-20 12:13:28 | <ski> | gpvs : anyway, perhaps we should first try to determine what you want, before diving into the how ? |
| 2020-09-20 12:13:40 | <edwardk> | Cale: i have it boiled down to one file now |
| 2020-09-20 12:14:08 | <edwardk> | https://www.irccloud.com/pastebin/KHWDco0s/BrokenVec.hs |
| 2020-09-20 12:14:23 | <edwardk> | that is standalone and doesn't need the types library i'm writing |
| 2020-09-20 12:14:45 | <Cale> | ah, cool |
| 2020-09-20 12:15:31 | <gpvs> | Cale, ski: ok, as far as I can see to get a uniform list of instances I *must* bind types like with multiparam class. What about getting a non-uniform list? Like when Cat can say [WordType0, WordType2]. |
| 2020-09-20 12:15:57 | <Cale> | gpvs: Well, what do those word types have in common? What are you going to do with the resulting list? |
| 2020-09-20 12:16:19 | <ski> | gpvs : you could do that, too, with existentials |
| 2020-09-20 12:16:22 | <gpvs> | ski: I want something like returning an array of objects confirming to interface in OO-kind stuff |
| 2020-09-20 12:16:27 | <Cale> | gpvs: You can think of a type as representing permissions to use the corresponding values in particular ways. If you don't know what type something is, it becomes impossible to observe |
| 2020-09-20 12:16:27 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 258 seconds) |
| 2020-09-20 12:16:36 | <ski> | gpvs : yea, that sounds like existentials |
| 2020-09-20 12:16:37 | → | PropositionJoe joins (~ConJoe@cm-84.215.192.230.getinternet.no) |
| 2020-09-20 12:16:49 | <gpvs> | Cale: those word types all are instances of AWord class |
| 2020-09-20 12:16:53 | <ski> | gpvs : however, often this is not a good idea / overkill. but you can do it |
| 2020-09-20 12:16:53 | <PropositionJoe> | Why do I have to write "`div`" instead of just div? |
| 2020-09-20 12:17:04 | <Cale> | Yeah, existentials give you one way to discard information about what type of thing you have |
| 2020-09-20 12:17:11 | <ski> | > div 18 7 -- PropositionJoe |
| 2020-09-20 12:17:14 | <lambdabot> | 2 |
| 2020-09-20 12:17:14 | <edwardk> | > div 4 3 |
| 2020-09-20 12:17:17 | <lambdabot> | 1 |
| 2020-09-20 12:17:18 | <edwardk> | works for me |
| 2020-09-20 12:17:21 | × | suppi quits (~suppi@2605:f700:40:c00::e6fc:6842) (Ping timeout: 244 seconds) |
| 2020-09-20 12:17:31 | <PropositionJoe> | so div is prefix "`div`" is infix? |
| 2020-09-20 12:17:34 | <ski> | yep |
| 2020-09-20 12:17:35 | <Cale> | data SomeWord where MkSomeWord :: AWord w => w -> SomeWord |
| 2020-09-20 12:17:37 | × | kritzefitz quits (~kritzefit@212.86.56.80) (Remote host closed the connection) |
| 2020-09-20 12:17:40 | <PropositionJoe> | thanks ski |
| 2020-09-20 12:17:48 | <edwardk> | putting backticks on makes anything infix |
| 2020-09-20 12:17:49 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2020-09-20 12:17:50 | <ski> | PropositionJoe : works for any identifier |
| 2020-09-20 12:17:51 | <Cale> | (that uses the GADTs extension) |
| 2020-09-20 12:17:53 | × | vicfred quits (~vicfred@unaffiliated/vicfred) (Remote host closed the connection) |
| 2020-09-20 12:18:20 | → | vicfred joins (~vicfred@unaffiliated/vicfred) |
| 2020-09-20 12:19:41 | <ski> | gpvs : `AWord' class currently has no methods (and no superclasses). so `exists type_word. AWord type_word *> ..type_word..' is kind of pointless, you can't get any information out. but perhaps your shown `AWord' was a mockup, and you'll actually have useful methods or superclasses ? |
| 2020-09-20 12:21:02 | <Cale> | gpvs: In my example, applying the MkSomeWord data constructor to a value whose type w is an instance of AWord will result in forgetting everything about which type w was, except that it had an instance of AWord, and then the only things you'll be allowed to do with the value when you get it out will be things you could do with any unknown instance of AWord |
| 2020-09-20 12:21:07 | <ski> | gpvs : "I want something like returning an array of objects confirming to interface in OO-kind stuff" -- do you actually need that ? how are you going to use the result of calls to `say' ? (Cale's question) |
| 2020-09-20 12:21:38 | <gpvs> | Cale, ski: looks like downcasting to me. Seems like I getting closer. I understand it doesn't make a lot sense in Haskell, just trying of how far it can extend. Yes, AWord is a mockup |
| 2020-09-20 12:21:44 | <Cale> | If you want to be more like OO, it might be more sensible just to make object types which correspond to whatever your classes would have been |
| 2020-09-20 12:21:58 | → | fulc927 joins (~fulc927@unaffiliated/fulc927) |
| 2020-09-20 12:22:01 | × | Rudd0 quits (~Rudd0@185.189.115.108) (Ping timeout: 246 seconds) |
| 2020-09-20 12:22:02 | <ski> | gpvs : there is no downcasting in Haskell, really |
| 2020-09-20 12:22:04 | <Cale> | Don't try to use Haskell classes as OO classes, they're not the same thing |
| 2020-09-20 12:22:29 | <Cale> | Instances of OO classes are values, instances of Haskell classes are types. |
| 2020-09-20 12:22:30 | <gpvs> | ski: yes, I sayed that making a parallel to what it would be for me in OO |
| 2020-09-20 12:22:32 | <ski> | gpvs : and how would you use downcasting, anyway ? test for particular types ? why not use a sum type ? |
| 2020-09-20 12:22:45 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 240 seconds) |
| 2020-09-20 12:22:58 | × | ystael quits (~ystael@209.6.50.55) (Ping timeout: 265 seconds) |
| 2020-09-20 12:23:05 | <Cale> | Haskell classes are a good bit like interfaces though |
| 2020-09-20 12:23:15 | tchouri | is now known as hekkaidekapus |
| 2020-09-20 12:23:17 | <Cale> | But usually it makes more sense not to start from there |
| 2020-09-20 12:23:21 | × | ericsagnes quits (~ericsagne@2405:6580:0:5100:2032:8cd9:bb36:4db2) (Ping timeout: 246 seconds) |
| 2020-09-20 12:23:40 | <Cale> | What methods were you going to put in the AWord class? |
| 2020-09-20 12:23:41 | <ski> | gpvs : if `AWord' is beefy enough for you to be able to do something sensible with values of an unknown type `type_word' that's an instance of `AWord', then existentials start to make more sense |
| 2020-09-20 12:23:50 | <gpvs> | ski, Cale: "data SomeWord where MkSomeWord :: AWord w => w -> SomeWord" ok, maybe 'downcasting' is not the best term. Let me call it 'specialization' then. |
| 2020-09-20 12:24:42 | <gpvs> | ski: yes, AWord in dpaste is a mockup |
| 2020-09-20 12:24:47 | → | suppi joins (~suppi@2605:f700:40:c00::e6fc:6842) |
| 2020-09-20 12:24:50 | <ski> | yea, i got that |
| 2020-09-20 12:25:06 | × | shatriff quits (~vitaliish@176.52.219.10) (Remote host closed the connection) |
| 2020-09-20 12:25:06 | → | __Joker joins (~Joker@180.151.105.65) |
| 2020-09-20 12:25:28 | <ski> | gpvs : by "downcasting" i meant being able to do e.g. `toAWordDog :: AWord w => w -> Maybe AWordDog' |
| 2020-09-20 12:25:47 | → | shatriff joins (~vitaliish@176.52.219.10) |
| 2020-09-20 12:25:48 | <gpvs> | Cale: I will not try to do OO with Haskell, pinkie-promise! :) Just looking at cases while learning. |
| 2020-09-20 12:25:54 | <ski> | gpvs : that is the kind of thing you had in mind, yes ? |
| 2020-09-20 12:26:57 | <gpvs> | ski: nodes of graph of different types and constructs which can reference each other regardless, relying on fact that all of them confirm to the basic interface |
| 2020-09-20 12:27:25 | <ski> | gpvs : which question is that an answer to ? |
| 2020-09-20 12:27:58 | <ski> | (it doesn't seem to obviously be about how to use downcasts, e.g.) |
| 2020-09-20 12:28:55 | <Cale> | gpvs: Well, I think doing OO with Haskell can be quite good in some cases. The encoding, if you do it right, is indistinguishable from ordinary functional programming. You have first class functions and you have record types. Put those together, and you can make records of methods which can be defined differently for each value you construct. |
| 2020-09-20 12:29:06 | <ski> | Cale : although you call interface methods on an object :) |
| 2020-09-20 12:29:14 | <Cale> | gpvs: i.e. you don't need subclasses to override method implementations |
| 2020-09-20 12:29:24 | <Cale> | (which is good, since you don't have subclasses) |
| 2020-09-20 12:29:55 | <gpvs> | ski: I misread 'that' as 'what', sorry. It seems like that. Have to research existentials and try in ghc. |
| 2020-09-20 12:30:13 | × | __Joker quits (~Joker@180.151.105.65) (Ping timeout: 264 seconds) |
| 2020-09-20 12:30:15 | <Cale> | I would honestly avoid existentials initially |
| 2020-09-20 12:30:26 | <Cale> | Most of the time, you won't really need them |
| 2020-09-20 12:30:37 | <ski> | @where existential-antipattern |
| 2020-09-20 12:30:37 | <lambdabot> | "Haskell Antipattern: Existential Typeclass" by Luke Palmer at <http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/> |
| 2020-09-20 12:31:36 | <gpvs> | ski, Cale: thank you for your help! Will research existentials and try them for my case, just to know it's there. If you wondering, the original idea was "nodes of graph of different types and constructs which can reference each other regardless, relying on fact that all of them confirm to the basic interface" |
| 2020-09-20 12:31:36 | <Cale> | gpvs: The important question to think about first is "what am I allowed to do with these things?" -- if you can figure out all the things you're allowed to do with a thing, then one of the ways of defining its type is just as a collection of the results of those operations |
| 2020-09-20 12:31:39 | <ski> | gpvs : if we saw the actual `AWord' class, or if you told how you were going to use the results of `say', or both, we might be able to give better advice |
All times are in UTC.