Logs: freenode/#haskell
| 2021-02-28 11:41:09 | <[exa]> | olligobber: yeah. Just to make this perfectly unambiguous for the downstream compiler |
| 2021-02-28 11:41:10 | → | srk joins (~sorki@gateway/tor-sasl/sorki) |
| 2021-02-28 11:41:15 | → | hexo joins (~hexo@gateway/tor-sasl/hexo) |
| 2021-02-28 11:41:53 | → | daffy80 joins (01c8aa98@1.200.170.152) |
| 2021-02-28 11:41:59 | <[exa]> | unfortunately the `import` statements cannot easily distinguish between external library and local file |
| 2021-02-28 11:42:03 | <daffy80> | boxscape ah okay I see |
| 2021-02-28 11:42:04 | → | wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2021-02-28 11:42:08 | <olligobber> | oh I see |
| 2021-02-28 11:42:56 | <[exa]> | olligobber: to fix that, cabal would need to pass explicit file lists of files that should not be touched in the build, which becomes rather clumsy with growing projects |
| 2021-02-28 11:43:18 | <olligobber> | yay it compiled |
| 2021-02-28 11:43:40 | <olligobber> | though my ghc-options got ignored... |
| 2021-02-28 11:44:46 | <daffy> | boxscape if I wanted to display the image, I would have to do in a separate function? because displayImage outputs type IO() but that doesn't match the type signature i added |
| 2021-02-28 11:45:05 | × | cartwright quits (~chatting@gateway/tor-sasl/cantstanya) (Remote host closed the connection) |
| 2021-02-28 11:46:18 | × | wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 245 seconds) |
| 2021-02-28 11:46:24 | <[exa]> | olligobber: actually I never used shared options like this so cannot tell (blind suggestion: bump cabal req version to one that supports it) |
| 2021-02-28 11:47:04 | <[exa]> | `common` is supported only since 2.2 |
| 2021-02-28 11:47:23 | <boxscape> | daffy you should be able to do it in the same function. displayImage has type `Image arr cs e -> IO ()` I'm guessing? |
| 2021-02-28 11:47:26 | → | cartwright joins (~chatting@gateway/tor-sasl/cantstanya) |
| 2021-02-28 11:47:38 | <daffy80> | yessir |
| 2021-02-28 11:48:17 | <olligobber> | [exa], ah, ty |
| 2021-02-28 11:48:54 | <[exa]> | olligobber: anyway, packaging is hard and the amount of surprise is often surprising. |
| 2021-02-28 11:49:54 | <boxscape> | daffy80 and you want this function you're in to return `IO (Image VS Y Double)`? |
| 2021-02-28 11:50:33 | <daffy80> | yeap, the same type that I read it as |
| 2021-02-28 11:52:23 | <boxscape> | daffy the last line in your do block should be a value of that type then, so if you want to display it first, you can write `do <first few lines> ioImg <- lastLine; displayImage lastLine; return lastLine` |
| 2021-02-28 11:52:27 | × | James_F1 quits (~James_F@139.28.218.148) (Remote host closed the connection) |
| 2021-02-28 11:52:29 | <boxscape> | where semicolons are newlines |
| 2021-02-28 11:52:58 | <boxscape> | ehh |
| 2021-02-28 11:52:59 | <boxscape> | wait |
| 2021-02-28 11:53:12 | <boxscape> | `do <first few lines> img <- lastLine; displayImage img; return lastLine` |
| 2021-02-28 11:53:18 | <boxscape> | ^ should have been this daffy80 |
| 2021-02-28 11:53:42 | × | daffy quits (01c8aa98@1.200.170.152) (Ping timeout: 240 seconds) |
| 2021-02-28 11:54:03 | <boxscape> | do let me know if that's not a comprehensible way of sharing code |
| 2021-02-28 11:54:29 | <daffy80> | sorry what is lastLine? |
| 2021-02-28 11:54:46 | <boxscape> | daffy80 just referring to the last line of your current do block in that function |
| 2021-02-28 11:54:52 | <daffy80> | oh haha |
| 2021-02-28 11:55:07 | <boxscape> | daffy80 oh sorry it's still wrong |
| 2021-02-28 11:55:15 | <boxscape> | `do <first few lines> img <- lastLine; displayImage img; return img` |
| 2021-02-28 11:55:20 | <boxscape> | should have been this.. |
| 2021-02-28 11:56:15 | <daffy80> | Ahh okay |
| 2021-02-28 11:56:30 | → | bergey joins (~user@pool-74-108-99-127.nycmny.fios.verizon.net) |
| 2021-02-28 11:56:31 | <daffy80> | Do I need to change the type signature accordingly? |
| 2021-02-28 11:56:41 | <daffy80> | Because I'm outputting something different |
| 2021-02-28 11:57:51 | <boxscape> | daffy80 you shouldn't have to - the type of displayImage is different, but if the last line is `return img`, that's what the type of that function is (the type of a do block is always the type of the last line). `<-` unwraps it from `IO` and `return` rewraps `img` into IO, so the type ought to be the same as before |
| 2021-02-28 11:57:55 | × | Varis quits (~Tadas@unaffiliated/varis) (Remote host closed the connection) |
| 2021-02-28 11:59:32 | <daffy80> | I meant like before when I was working on getting fromList to work, I changed the type signature , do I keep that? |
| 2021-02-28 11:59:57 | <boxscape> | daffy80 if my mental image of what your code looks like is correct then yes, you keep that |
| 2021-02-28 12:00:16 | <daffy80> | ok I see |
| 2021-02-28 12:00:53 | <daffy80> | So <- allows you to extract something from IO? |
| 2021-02-28 12:01:08 | <daffy80> | But when the do block ends it still outputs as IO? |
| 2021-02-28 12:01:35 | × | sphalerite quits (~sphalerit@NixOS/user/lheckemann) (Quit: updates!) |
| 2021-02-28 12:01:45 | × | bergey quits (~user@pool-74-108-99-127.nycmny.fios.verizon.net) (Ping timeout: 264 seconds) |
| 2021-02-28 12:02:49 | <boxscape> | daffy80 technically <- is syntactic sugar for the >>= function, but you'll learn about that when you learn about monads. The type of an IO do block is always `IO (something)`, but inside the IO block, you can "get rid" of the IO wrapping with `<-`. But the type of the last line has to be `IO (something)`, so in this case we have to use the `return` |
| 2021-02-28 12:02:49 | <boxscape> | function to wrap it back into IO so the type is correct. |
| 2021-02-28 12:03:17 | <boxscape> | (to be clear, it has very little to do with the `return` keyword in other languages) |
| 2021-02-28 12:03:56 | <daffy80> | oh |
| 2021-02-28 12:04:02 | → | kritzefitz joins (~kritzefit@212.86.56.80) |
| 2021-02-28 12:04:12 | <daffy80> | Yeah I've been treating <- as an assignment operator |
| 2021-02-28 12:04:42 | <boxscape> | it is meant to be reminiscent of that though it works fairly differently |
| 2021-02-28 12:05:24 | <boxscape> | do-blocks are meant to look like imperative code, hence also the choice of the `return` name |
| 2021-02-28 12:05:38 | <daffy80> | I see |
| 2021-02-28 12:05:48 | → | int80h joins (uid148779@gateway/web/irccloud.com/x-xjmwrihbawesmufs) |
| 2021-02-28 12:06:57 | <daffy80> | what is the difference between = and <- then? I guess you can use <- to work in the IO monad while = doesn't allow you to? |
| 2021-02-28 12:07:47 | <boxscape> | you can use `let x = something` inside a do block. This is somewhat similar to `y <- something`, but if something has type `IO A`, then `x :: IO A` and `y :: A`. |
| 2021-02-28 12:08:26 | <daffy80> | ahh ok |
| 2021-02-28 12:08:34 | <boxscape> | (so if you want to pass `something` to a function that expects an A, not an IO A, you need to use <- to get access to it) |
| 2021-02-28 12:08:47 | <daffy80> | I see |
| 2021-02-28 12:08:54 | <daffy80> | This kind of reminds me of pointer access |
| 2021-02-28 12:09:11 | <__monty__> | That's very different. |
| 2021-02-28 12:09:11 | → | sphalerite joins (~sphalerit@NixOS/user/lheckemann) |
| 2021-02-28 12:09:22 | <__monty__> | Think of it as passing an argument to a function. |
| 2021-02-28 12:09:26 | <hugo> | 'do x <- something; return x' is equal to 'something >>= (\x -> return x)' |
| 2021-02-28 12:09:31 | <__monty__> | Don't try to equate it with concepts you have from other languages. |
| 2021-02-28 12:09:45 | <xsperry> | which is equal to 'something' :) |
| 2021-02-28 12:09:48 | <hugo> | As people have said above, bind (>>=) unwraps the monad context from a value |
| 2021-02-28 12:10:07 | <hugo> | xsperry: I know, but minimum viable example ;) |
| 2021-02-28 12:10:18 | <daffy80> | and <- is just syntactic sugar for bind? |
| 2021-02-28 12:10:41 | <hugo> | daffy80: yes. The entire 'do' notatation is just syntactic sugar for bind |
| 2021-02-28 12:10:47 | <boxscape> | @undo do x <- something; return x |
| 2021-02-28 12:10:47 | <lambdabot> | something >>= \ x -> return x |
| 2021-02-28 12:11:31 | <boxscape> | @undo img <- lastLine; displayImage img; return img |
| 2021-02-28 12:11:31 | <lambdabot> | <unknown>.hs:1:5:Parse error: <- |
| 2021-02-28 12:11:37 | <boxscape> | @undo do img <- lastLine; displayImage img; return img |
| 2021-02-28 12:11:37 | <lambdabot> | lastLine >>= \ img -> displayImage img >> return img |
| 2021-02-28 12:11:45 | <xsperry> | daffy80, did you try using do and <- with monads other than IO? |
| 2021-02-28 12:11:59 | × | xff0x quits (~xff0x@2001:1a81:5349:9200:2ca8:4ef3:12c9:ba81) (Ping timeout: 272 seconds) |
| 2021-02-28 12:12:00 | <daffy80> | no, im just getting into haskell |
| 2021-02-28 12:12:28 | → | xff0x joins (~xff0x@2001:1a81:5349:9200:2806:fad1:e222:a1c8) |
| 2021-02-28 12:12:40 | × | sh9 quits (~sh9@softbank060116136158.bbtec.net) (Quit: WeeChat 2.8) |
| 2021-02-28 12:12:44 | × | knupfer quits (~Thunderbi@200116b82cc9eb004cd887aa2955feba.dip.versatel-1u1.de) (Ping timeout: 240 seconds) |
| 2021-02-28 12:13:23 | <hugo> | Try 'do Just 10; Nothing; Just 20' |
| 2021-02-28 12:13:56 | <Aleksejs> | can I define types in lambdabot expressions? |
| 2021-02-28 12:14:08 | <boxscape> | daffy80 are you familiar with list comprehensions? |
| 2021-02-28 12:14:38 | <boxscape> | @let data Foo124 = Foo124 |
| 2021-02-28 12:14:40 | <daffy80> | I've heard of the term yes |
| 2021-02-28 12:14:40 | <lambdabot> | Defined. |
| 2021-02-28 12:14:52 | <boxscape> | ^ Aleksejs |
| 2021-02-28 12:14:59 | <Aleksejs> | nice |
| 2021-02-28 12:15:58 | <daffy80> | hugo in GHCi? |
| 2021-02-28 12:16:08 | <boxscape> | daffy80 list comprehensions in haskell are also more or less do notation, i.e. [ x + y | x <- [1..5] , y <- [1..6] ] is the same as `do x <- [1..5]; y <- [1..6]; return x + y`, so lists are another example of where do notation can be nice |
| 2021-02-28 12:16:31 | <boxscape> | IO is just the place where it comes up most often |
All times are in UTC.