Logs: freenode/#haskell
| 2021-02-28 12:17:07 | <daffy80> | So the do notation is just for readability? |
| 2021-02-28 12:17:12 | <boxscape> | yes |
| 2021-02-28 12:17:33 | <daffy80> | Ahh |
| 2021-02-28 12:17:47 | → | clog joins (~nef@bespin.org) |
| 2021-02-28 12:18:49 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 245 seconds) |
| 2021-02-28 12:19:12 | <hugo> | daffy80: Raw do-notations in GHCi is clumsy. Try writing the following to a file and compiling it instead: |
| 2021-02-28 12:19:15 | <hugo> | main :: IO () |
| 2021-02-28 12:19:17 | <hugo> | main = putStrLn . show $ do Just 10; Nothing; Just 20 |
| 2021-02-28 12:19:21 | <boxscape> | Aleksejs fwiw you may find yahb more convenient which is just directly a bridge to ghci |
| 2021-02-28 12:19:31 | <boxscape> | % data Foo123 = FOo123 |
| 2021-02-28 12:19:31 | <yahb> | boxscape: |
| 2021-02-28 12:21:00 | <daffy80> | it returns Nothing when I run that hugo |
| 2021-02-28 12:21:59 | <hugo> | daffy80: That's expected. I wanted to show an example of do (and bind) on a different monad than IO |
| 2021-02-28 12:22:19 | → | Deide joins (~Deide@217.155.19.23) |
| 2021-02-28 12:23:02 | <xsperry> | > do x <- Just 10; y <- Just 20; return (x+y) |
| 2021-02-28 12:23:04 | <lambdabot> | Just 30 |
| 2021-02-28 12:23:09 | <xsperry> | > do x <- Nothing; y <- Just 20; return (x+y) |
| 2021-02-28 12:23:11 | <daffy80> | Hmm what is Just doing? |
| 2021-02-28 12:23:11 | <lambdabot> | Nothing |
| 2021-02-28 12:23:47 | <hugo> | daffy80: Just and Nothing are the two instances of the Maybe datatype. Which represent the posibility of a value being there |
| 2021-02-28 12:24:03 | <xsperry> | Nothing is roughly equivalent to null reference in other languages. and Just is a constructor that indicates there's a value in Maybe |
| 2021-02-28 12:24:19 | <daffy80> | I see |
| 2021-02-28 12:24:38 | <daffy80> | So Maybe is a monad? |
| 2021-02-28 12:24:44 | <xsperry> | yes |
| 2021-02-28 12:25:02 | → | mputz joins (~Thunderbi@dslb-088-064-063-125.088.064.pools.vodafone-ip.de) |
| 2021-02-28 12:25:28 | <xsperry> | difference being that there's no all-encompassing null that is included in every type, you have to use Maybe to get null (Nothing) |
| 2021-02-28 12:27:02 | → | SchwarzeLocke joins (~SchwarzeL@178.239.168.171) |
| 2021-02-28 12:27:46 | ← | int80h parts (uid148779@gateway/web/irccloud.com/x-xjmwrihbawesmufs) () |
| 2021-02-28 12:27:46 | → | sh9 joins (~sh9@softbank060116136158.bbtec.net) |
| 2021-02-28 12:28:01 | <daffy80> | right |
| 2021-02-28 12:28:22 | <xsperry> | notice the similarity to IO do block, Just 20 is Maybe a, and x <- Just 20, x is a (where a is Num a => a, some numerical type) |
| 2021-02-28 12:30:21 | <daffy80> | so any instance of a Monad can be used in a do block ? |
| 2021-02-28 12:30:33 | <xsperry> | yes |
| 2021-02-28 12:31:10 | <daffy80> | ic ic |
| 2021-02-28 12:31:34 | × | cheater quits (~user@unaffiliated/cheater) (Ping timeout: 260 seconds) |
| 2021-02-28 12:32:52 | <boxscape> | (though only one Monad per do block) |
| 2021-02-28 12:33:24 | <boxscape> | i.e. you can't use <- to unwrap `IO String` if the do Block is supposed to return `Maybe Int` in the end |
| 2021-02-28 12:33:46 | → | knupfer joins (~Thunderbi@200116b82cc9eb0070e901fffe4f30ff.dip.versatel-1u1.de) |
| 2021-02-28 12:34:00 | <daffy80> | what determines what is supposed to return ? |
| 2021-02-28 12:34:06 | <daffy80> | whichever one comes first? |
| 2021-02-28 12:34:23 | <boxscape> | the type of the last line is the type of the do block |
| 2021-02-28 12:34:26 | × | knupfer quits (~Thunderbi@200116b82cc9eb0070e901fffe4f30ff.dip.versatel-1u1.de) (Remote host closed the connection) |
| 2021-02-28 12:34:31 | <daffy80> | oh |
| 2021-02-28 12:34:44 | <boxscape> | so if you write `putStrLn "hi"` as last line, it will be a IO do block |
| 2021-02-28 12:34:51 | <daffy80> | Ah ok |
| 2021-02-28 12:35:09 | <hugo> | For me to properly get my head around all the intricacies of bind I had to reimplement it in a different language |
| 2021-02-28 12:35:14 | <boxscape> | though on the other hand if you write `line <- getLine` somewhere in the middle, it will also infer that it should be an IO do block, it'll just complain if the last line doesn't match that |
| 2021-02-28 12:35:44 | <daffy80> | hugo yeah I feel like I'm thinking of everything in terms of other languages |
| 2021-02-28 12:36:26 | <daffy80> | right so the main thing to remember is to only have one monad per do block |
| 2021-02-28 12:36:39 | → | nineonine joins (~nineonine@2604:3d08:7785:9600:8c3e:8d1a:de68:76d3) |
| 2021-02-28 12:36:40 | <hugo> | daffy |
| 2021-02-28 12:36:40 | <boxscape> | right |
| 2021-02-28 12:37:52 | <hugo> | daffy80: reimplementing bind in a different language was mostly to avoid implementing bind in terms of bind |
| 2021-02-28 12:38:52 | <hugo> | Also, the much more relaxed type system of scheme (which was what I wrote it in) allowed me to experiment with mixing types inside a do block, and got to see why it doesn't work |
| 2021-02-28 12:40:17 | <daffy80> | I find the type system in haskell tough to get used to |
| 2021-02-28 12:40:39 | <boxscape> | I find it so hard to go back to less strict systems at this point |
| 2021-02-28 12:40:55 | <daffy80> | oh really |
| 2021-02-28 12:41:02 | <Uniaika> | yeah it's a pain :/ |
| 2021-02-28 12:41:15 | <daffy80> | Shouldn't it go the other way |
| 2021-02-28 12:41:24 | <Uniaika> | you benefit from so much without having to compromise because you also have powerful abstractions |
| 2021-02-28 12:41:26 | × | nineonine quits (~nineonine@2604:3d08:7785:9600:8c3e:8d1a:de68:76d3) (Ping timeout: 264 seconds) |
| 2021-02-28 12:41:26 | × | ixlun quits (~user@213.205.241.12) (Read error: Connection reset by peer) |
| 2021-02-28 12:41:29 | <hugo> | The type system can be a hindrance until you get your head around it. |
| 2021-02-28 12:41:51 | <boxscape> | every time I make a silly mistake I think "-.- this wouldn't have happened with haskell" |
| 2021-02-28 12:41:51 | → | cheater joins (~user@unaffiliated/cheater) |
| 2021-02-28 12:42:12 | <boxscape> | (except for the silly mistakes that still coul have happened with haskell :P) |
| 2021-02-28 12:42:15 | <hugo> | I only just recently learned to actually leaverage the type system to my advantage |
| 2021-02-28 12:43:31 | <daffy80> | what are some of those advantages? |
| 2021-02-28 12:45:13 | <hugo> | In my current project I needed to parse messages of varying type. My code more or less looks like 'decoder = F <$> decoder <*> decoder <*> decoder' |
| 2021-02-28 12:45:36 | × | mputz quits (~Thunderbi@dslb-088-064-063-125.088.064.pools.vodafone-ip.de) (Ping timeout: 240 seconds) |
| 2021-02-28 12:45:54 | → | ixlun joins (~user@213.205.241.12) |
| 2021-02-28 12:45:54 | <hugo> | Where each instance of decoder has a different return type. Decided by F's type |
| 2021-02-28 12:46:33 | → | o1lo01ol1o joins (~o1lo01ol1@89.214.221.60) |
| 2021-02-28 12:46:33 | × | o1lo01ol1o quits (~o1lo01ol1@89.214.221.60) (Client Quit) |
| 2021-02-28 12:46:39 | <Uniaika> | hugo: applicative functors <3 |
| 2021-02-28 12:47:05 | → | daffy joins (01c8aa98@1.200.170.152) |
| 2021-02-28 12:47:22 | × | daffy80 quits (01c8aa98@1.200.170.152) (Quit: Connection closed) |
| 2021-02-28 12:48:01 | → | o1lo01ol1o joins (~o1lo01ol1@89.214.221.60) |
| 2021-02-28 12:49:36 | → | kam1 joins (~kam1@5.125.126.175) |
| 2021-02-28 12:51:38 | <daffy> | @boxs |
| 2021-02-28 12:51:38 | <lambdabot> | Maybe you meant: docs b52s |
| 2021-02-28 12:51:42 | <daffy> | oops |
| 2021-02-28 12:51:56 | <daffy> | boxscape i tried your suggestion but vscode is screaming at me |
| 2021-02-28 12:52:07 | <boxscape> | oh no! |
| 2021-02-28 12:52:10 | <boxscape> | can you paste the code? |
| 2021-02-28 12:52:11 | <daffy> | i think i misunderstood what you were saying lol |
| 2021-02-28 12:52:24 | <boxscape> | on https://paste.tomsmeding.com/ or similar |
| 2021-02-28 12:52:48 | → | heatsink joins (~heatsink@2600:1700:bef1:5e10:692f:34e4:c65a:92f2) |
| 2021-02-28 12:53:59 | <daffy> | https://paste.tomsmeding.com/GP2eJ91K |
| 2021-02-28 12:55:10 | → | viluon joins (uid453725@gateway/web/irccloud.com/x-nrcpcvymghsotxnv) |
| 2021-02-28 12:55:25 | <boxscape> | daffy ah, looks like you just need `return fin` instead of `return img` |
| 2021-02-28 12:56:51 | <boxscape> | daffy since displayImage returns `IO ()`, the type of `img` in this case becomes `()`, and the type of `return img` is `IO ()` again, whereas the type of `fin` is `Image ...`, so `return fin` gives you `IO (Image ...)`, which is what you need |
| 2021-02-28 12:56:56 | × | heatsink quits (~heatsink@2600:1700:bef1:5e10:692f:34e4:c65a:92f2) (Ping timeout: 240 seconds) |
| 2021-02-28 12:57:01 | <daffy> | it worked but how come? isn't img holding the result of displayImage |
| 2021-02-28 12:57:11 | <boxscape> | indeed |
| 2021-02-28 12:57:17 | <boxscape> | but you want to return the result of fromLists |
| 2021-02-28 12:57:21 | <boxscape> | not the result of displayImage |
| 2021-02-28 12:57:54 | <boxscape> | the useful part of displayImage is that it has a side effect (i.e. displaying the image), not that it returns something interesting |
| 2021-02-28 12:58:49 | → | ambiso9 joins (~ambiso@209.182.239.205) |
| 2021-02-28 12:58:59 | <boxscape> | in fact, its return value doesn't contain any interesting information, since there's only one possible value that's in `()` -- that value is also called `()`. functions that have return type `IO ()` are like functions that have return type void in C or Java |
All times are in UTC.