Logs: freenode/#haskell
| 2021-04-08 11:52:26 | → | zebrag joins (~inkbottle@aaubervilliers-654-1-2-51.w83-200.abo.wanadoo.fr) |
| 2021-04-08 11:52:39 | → | nut joins (~user@roc37-h01-176-170-197-243.dsl.sta.abo.bbox.fr) |
| 2021-04-08 11:53:21 | → | pfurla joins (~pfurla@116.15.195.173.client.static.strong-in52.as13926.net) |
| 2021-04-08 11:54:40 | → | solvr joins (57e3c46d@87.227.196.109) |
| 2021-04-08 11:54:41 | × | minoru_shiraeesh quits (~shiraeesh@109.166.57.223) (Read error: Connection reset by peer) |
| 2021-04-08 11:55:02 | → | minoru_shiraeesh joins (~shiraeesh@109.166.57.223) |
| 2021-04-08 11:57:17 | → | dexterlb_ joins (~dexterlb@2a01:9e40:2:2::2) |
| 2021-04-08 11:57:25 | × | minoru_shiraeesh quits (~shiraeesh@109.166.57.223) (Client Quit) |
| 2021-04-08 11:57:29 | → | royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) |
| 2021-04-08 12:00:42 | <rann> | hi haskell peeps, quick question (very new to haskell). suppose I have a collection of handlers that take input and produce output. suppose that I want each handler in the collection (an ordered list) to call each other; how would you go about that in haskell? |
| 2021-04-08 12:00:47 | × | plutoniix quits (~q@184.82.198.236) (Quit: Leaving) |
| 2021-04-08 12:01:41 | × | Kronic quits (sid480486@gateway/web/irccloud.com/x-sohccpvegokjgbzc) (Quit: Connection closed for inactivity) |
| 2021-04-08 12:02:20 | × | ukari quits (~ukari@unaffiliated/ukari) (Remote host closed the connection) |
| 2021-04-08 12:02:26 | × | royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Ping timeout: 265 seconds) |
| 2021-04-08 12:03:26 | → | ukari joins (~ukari@unaffiliated/ukari) |
| 2021-04-08 12:03:42 | <jacks2> | what is the type of the handler? |
| 2021-04-08 12:04:03 | × | nrh^ quits (nrh@ip98-184-89-2.mc.at.cox.net) () |
| 2021-04-08 12:04:05 | <rann> | I haven't defined that yet, could esentially be a function |
| 2021-04-08 12:05:43 | <rann> | so, say [f1, f2, f3], then f1 calls f2, which in turn is triggered to call f3, (no different types of arguments, all string in, string out, which serves this example) |
| 2021-04-08 12:09:01 | → | nbloomf joins (~nbloomf@2600:1700:ad14:3020:5145:4fc3:585b:3fa8) |
| 2021-04-08 12:09:15 | <jacks2> | > let handlers = [(++"!") . map toUpper] in foldr (.) (const "hello") handlers "" |
| 2021-04-08 12:09:17 | <lambdabot> | "HELLO!" |
| 2021-04-08 12:10:08 | → | geekosaur joins (82650c7a@130.101.12.122) |
| 2021-04-08 12:13:11 | × | pfurla quits (~pfurla@116.15.195.173.client.static.strong-in52.as13926.net) (Ping timeout: 240 seconds) |
| 2021-04-08 12:14:18 | <jacks2> | > let applyHandlers handlers s = foldr (.) (const s) handlers ""; in applyHandlers [(++"!") . map toUpper] "hello" |
| 2021-04-08 12:14:20 | <lambdabot> | "HELLO!" |
| 2021-04-08 12:15:00 | → | dsrt^ joins (dsrt@ip98-184-89-2.mc.at.cox.net) |
| 2021-04-08 12:17:29 | <jacks2> | should have typed [(++"!"), map toUpper], ie, a list of two String -> String functions, but, it also worked with (.) :) |
| 2021-04-08 12:17:47 | → | royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) |
| 2021-04-08 12:18:03 | → | stef204 joins (~stef204@unaffiliated/stef-204/x-384198) |
| 2021-04-08 12:18:36 | → | BosonCollider joins (~olofs@90-227-86-119-no542.tbcn.telia.com) |
| 2021-04-08 12:18:45 | <BosonCollider> | I've been wondering |
| 2021-04-08 12:19:25 | <BosonCollider> | could you design something similar to ML functors but for typeclass implementations, if you view typeclasses like module signatures? |
| 2021-04-08 12:19:48 | <geekosaur> | backpack? |
| 2021-04-08 12:20:02 | → | frozenErebus joins (~frozenEre@37.231.244.249) |
| 2021-04-08 12:20:35 | <geekosaur> | not quite the same thing but close |
| 2021-04-08 12:22:06 | <BosonCollider> | I don't really mean exactly implementing modules, but something like functorname : (quantifiers, typeclass constraints) -> Typeclass a b ... { body} |
| 2021-04-08 12:22:45 | → | waleee-cl joins (uid373333@gateway/web/irccloud.com/x-eacnnlwpubqgsxmt) |
| 2021-04-08 12:23:03 | <BosonCollider> | so that you can write a generic implementation of the typeclass on the right, and substitute in any specific type instead of implementing it by hand |
| 2021-04-08 12:23:37 | <geekosaur> | that's been done using Generics, yes |
| 2021-04-08 12:25:09 | <geekosaur> | or the way Foldable does it, just drop in a toList and the rest can be (un-optimally) generically implemented, or you can provide optimized versions |
| 2021-04-08 12:26:13 | <BosonCollider> | no, that's not what I mean |
| 2021-04-08 12:26:26 | × | Gurkenglas quits (~Gurkengla@unaffiliated/gurkenglas) (Ping timeout: 240 seconds) |
| 2021-04-08 12:26:40 | × | nbloomf quits (~nbloomf@2600:1700:ad14:3020:5145:4fc3:585b:3fa8) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2021-04-08 12:26:59 | × | berberman quits (~berberman@unaffiliated/berberman) (Ping timeout: 248 seconds) |
| 2021-04-08 12:27:04 | <BosonCollider> | because this would allow you to pick an implementation if you have conflicting generic implementations |
| 2021-04-08 12:27:07 | → | berberman_ joins (~berberman@unaffiliated/berberman) |
| 2021-04-08 12:28:51 | <rann> | jacks2: thanks! |
| 2021-04-08 12:29:03 | <BosonCollider> | like for example, if I have a Heap typeclass and want to implement monofoldable for any type that implements Heap (foldable doesn't work here because of the Ord constraint, but that's a separate issue) |
| 2021-04-08 12:29:44 | → | kenanmarasli joins (1fdf0dda@31.223.13.218) |
| 2021-04-08 12:31:53 | <BosonCollider> | then I can't implement monofoldable for all instances of heap for a number of reasons from conflicting implementations to orphan impls etc etc |
| 2021-04-08 12:32:53 | <kenanmarasli> | I don't know if this is a very noob question, but why is there an ambiguity problem with this code here? |
| 2021-04-08 12:32:54 | <kenanmarasli> | `sumList = foldl (\x y->x+y) 0 |
| 2021-04-08 12:32:54 | <kenanmarasli> | prodList = foldl (\x y->x*y) 1 |
| 2021-04-08 12:32:55 | <kenanmarasli> | main = print $ sumList [1,2,3]` |
| 2021-04-08 12:32:55 | <kenanmarasli> | Error: |
| 2021-04-08 12:32:56 | <kenanmarasli> | `689417354/source.hs:3:12: error: |
| 2021-04-08 12:32:56 | <BosonCollider> | but what this would do is allow someone to take an implementation I wrote and specify "this type uses this named implementation from X" |
| 2021-04-08 12:32:56 | <kenanmarasli> | • Ambiguous type variable ‘t0’ arising from a use of ‘foldl’ |
| 2021-04-08 12:32:57 | <kenanmarasli> | prevents the constraint ‘(Foldable t0)’ from being solved. |
| 2021-04-08 12:32:57 | <kenanmarasli> | Relevant bindings include |
| 2021-04-08 12:32:58 | <kenanmarasli> | prodList :: t0 Integer -> Integer |
| 2021-04-08 12:32:58 | <kenanmarasli> | (bound at 689417354/source.hs:3:1) |
| 2021-04-08 12:32:59 | <kenanmarasli> | Probable fix: use a type annotation to specify what ‘t0’ should be. |
| 2021-04-08 12:32:59 | <kenanmarasli> | These potential instances exist: |
| 2021-04-08 12:33:00 | <kenanmarasli> | instance Foldable (Either a) -- Defined in ‘Data.Foldable’ |
| 2021-04-08 12:33:00 | <kenanmarasli> | instance Foldable Maybe -- Defined in ‘Data.Foldable’ |
| 2021-04-08 12:33:01 | <kenanmarasli> | instance Foldable ((,) a) -- Defined in ‘Data.Foldable’ |
| 2021-04-08 12:33:01 | <kenanmarasli> | ...plus one other |
| 2021-04-08 12:33:02 | <kenanmarasli> | ...plus 22 instances involving out-of-scope types |
| 2021-04-08 12:33:15 | <kenanmarasli> | Ah damn it I thought it would markdown properly |
| 2021-04-08 12:33:57 | <geekosaur> | please don't paste into the channel |
| 2021-04-08 12:34:01 | <geekosaur> | @where paste |
| 2021-04-08 12:34:01 | <lambdabot> | Help us help you: please paste full code, input and/or output at e.g. https://paste.tomsmeding.com |
| 2021-04-08 12:34:15 | <kenanmarasli> | Alright, sorry about that |
| 2021-04-08 12:34:29 | <geekosaur> | anyway the usual cause of that is you need to specify that you want a list |
| 2021-04-08 12:35:01 | <geekosaur> | including the code that caused that error would help |
| 2021-04-08 12:35:34 | <rann> | jacks2: what does (++"!") do? |
| 2021-04-08 12:35:42 | <BosonCollider> | I also see this pop up in Rust a lot where a common pattern is writing a macro that implements a typeclass |
| 2021-04-08 12:35:48 | <rann> | just add the "!"? |
| 2021-04-08 12:35:52 | <BosonCollider> | or trait over there |
| 2021-04-08 12:35:56 | <geekosaur> | rann, it just appends the "!" |
| 2021-04-08 12:35:57 | <lortabac> | BosonCollider: I'm not 100% sure I understand, but it seems that DerivingVia can be used to achieve something similar |
| 2021-04-08 12:36:17 | <geekosaur> | it's a section on the (++) operator |
| 2021-04-08 12:36:42 | → | machinedgod joins (~machinedg@135-23-192-217.cpe.pppoe.ca) |
| 2021-04-08 12:36:45 | <geekosaur> | (you can look up "haskell section operator" for full details, but it's basically partial application applied to an operator) |
| 2021-04-08 12:37:15 | <kenanmarasli> | geekosaur thank you sir. I have the code and error here: https://paste.tomsmeding.com/M5WXR9Im |
| 2021-04-08 12:37:49 | → | pfurla_ joins (~pfurla@ool-182ed2e2.dyn.optonline.net) |
| 2021-04-08 12:39:23 | <kenanmarasli> | Here I don't understand why I need to specify that I want a list, when it works without the second function definition |
| 2021-04-08 12:39:26 | <geekosaur> | oh, this is the monomorphism restriction operating on prodList |
| 2021-04-08 12:39:36 | × | raichoo quits (~raichoo@dslb-092-073-205-046.092.073.pools.vodafone-ip.de) (Quit: Lost terminal) |
| 2021-04-08 12:39:41 | <geekosaur> | it can guess for sumList because you apply it to a list later |
| 2021-04-08 12:39:51 | → | royal_screwup215 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) |
| 2021-04-08 12:40:15 | <geekosaur> | the root of the problem is that you don't specify parameters to either sumList or prodList, so it wants to monomorphize their types on the assumption that you want sharing to occur |
| 2021-04-08 12:40:30 | → | LKoen joins (~LKoen@65.250.88.92.rev.sfr.net) |
| 2021-04-08 12:40:36 | <geekosaur> | so if you eta-expand them (prodList xs = ... xs) things will work |
| 2021-04-08 12:40:56 | <kenanmarasli> | I see, thank you very much :) |
| 2021-04-08 12:41:41 | <kenanmarasli> | Again, thank you for telling me how to share code here. Won't paste again :) |
| 2021-04-08 12:41:41 | × | star_cloud quits (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com) (Ping timeout: 240 seconds) |
| 2021-04-08 12:42:38 | <geekosaur> | basically, without parameters it doesn't "look like a function" so it assumes you don't want it to behave like a function, but like a value. so make it look like a function. or you can specify the type with a type signature to tell it what you want to do instead of having it guess via the monomorphism restriction |
All times are in UTC.