Logs: freenode/#haskell
| 2020-11-19 05:54:54 | <dsal> | Do you understand what `repeat getLine` means? |
| 2020-11-19 05:55:01 | <dsal> | :t repeat getLine |
| 2020-11-19 05:55:04 | <lambdabot> | [IO String] |
| 2020-11-19 05:55:35 | <n0042> | Yeah it's a list of getLine functions. I was trying to find some way to call getLine a certain amount of times in a row. |
| 2020-11-19 05:55:43 | <n0042> | But I'm not sure I'm on the right track |
| 2020-11-19 05:55:50 | <dsal> | It's a list of actions that produce strings. |
| 2020-11-19 05:56:31 | <dsal> | What type would make more sense here? |
| 2020-11-19 05:57:02 | <dsal> | (it's often easier to think about what you want than to struggle with the parts you have) |
| 2020-11-19 05:57:11 | <n0042> | Strings themselves, I suppose. |
| 2020-11-19 05:57:33 | × | hidedagger quits (~nate@unaffiliated/hidedagger) (Quit: WeeChat 2.9) |
| 2020-11-19 05:57:44 | <dsal> | What does "Strings themselves" mean? |
| 2020-11-19 05:57:56 | <n0042> | The assignment's program flow is: Input buffer size and number of packets -> input line for each packet -> calculate the processing time for each packet or if it was dropped -> output a line for each packet. |
| 2020-11-19 05:58:00 | <dsal> | (Haskell is an ideal language to speak here to avoid misunderstanding) |
| 2020-11-19 05:58:08 | → | hidedagger joins (~nate@unaffiliated/hidedagger) |
| 2020-11-19 05:58:22 | <n0042> | The input/output is pre-determined and I can't change how it works because it's an automated system that collectes from stdin during runtime. |
| 2020-11-19 05:58:38 | <dsal> | None of these details are relevant to what you're trying to do. |
| 2020-11-19 05:58:42 | <n0042> | We got to choose our language though and I figured it's be a good way to dive in head first with haskell |
| 2020-11-19 05:59:23 | <zyklotomic> | i'm saying in case no one pointed out the distinction, `repeat getLine` is returing a list of the actions, but nothing is executing those actions |
| 2020-11-19 05:59:48 | <dsal> | But taking a step back and identifying what you actually want might make this easy. |
| 2020-11-19 05:59:52 | <n0042> | I know. I'm not sure how to execute those actions once I have them. |
| 2020-11-19 06:00:00 | <zyklotomic> | yup that is the crux (i think) |
| 2020-11-19 06:00:10 | <dsal> | Stating clearly what you want would speed things up a lot. |
| 2020-11-19 06:00:38 | <n0042> | What I want is to get n-lines from stdin, separated by newline characters. |
| 2020-11-19 06:00:58 | <n0042> | As [Char] types |
| 2020-11-19 06:01:17 | <n0042> | Which I will then parse into [Int] types |
| 2020-11-19 06:01:37 | <dsal> | OK, closer... Less English, more Haskell. How would you describe the above in Haskell? |
| 2020-11-19 06:01:44 | <dsal> | :t getLine -- e.g. |
| 2020-11-19 06:01:46 | <lambdabot> | IO String |
| 2020-11-19 06:01:54 | <n0042> | Well, a single line is easy: line <- getLine |
| 2020-11-19 06:01:58 | <dsal> | So, `getLine` is `IO String` |
| 2020-11-19 06:02:04 | <dsal> | What type are you looking for |
| 2020-11-19 06:02:05 | <dsal> | ? |
| 2020-11-19 06:02:06 | × | hidedagger quits (~nate@unaffiliated/hidedagger) (Client Quit) |
| 2020-11-19 06:02:35 | → | hidedagger joins (~nate@unaffiliated/hidedagger) |
| 2020-11-19 06:02:58 | <n0042> | String |
| 2020-11-19 06:03:07 | <zyklotomic> | bigger |
| 2020-11-19 06:03:20 | <n0042> | [String]? |
| 2020-11-19 06:03:21 | <zyklotomic> | think a bit higher |
| 2020-11-19 06:03:23 | <zyklotomic> | yup |
| 2020-11-19 06:03:37 | <dsal> | Closer, but it isn't pure. |
| 2020-11-19 06:03:40 | <dsal> | You're doing IO to get there. |
| 2020-11-19 06:03:56 | <n0042> | I am intrigued. Tell me more. |
| 2020-11-19 06:04:03 | <dsal> | :t getLine |
| 2020-11-19 06:04:04 | <lambdabot> | IO String |
| 2020-11-19 06:04:31 | <dsal> | That's not a String. |
| 2020-11-19 06:04:37 | <n0042> | line <- getLine results in String. |
| 2020-11-19 06:04:49 | <n0042> | according to my REPL, the type of line is String after that |
| 2020-11-19 06:05:03 | <dsal> | Eh. That's slightly confusing. |
| 2020-11-19 06:05:20 | <n0042> | Which is why I thought I might be able to turn [getLine] into [String] somehow |
| 2020-11-19 06:05:34 | <zyklotomic> | the <- does some magic lol |
| 2020-11-19 06:05:56 | <dsal> | It's also not a complete useful expression. The repl lets you do things that don't fully make sense. |
| 2020-11-19 06:06:08 | <dsal> | @undo do { line <- getLine } |
| 2020-11-19 06:06:08 | <lambdabot> | <unknown>.hs:1:23:Parse error: Last statement in a do-block must be an expression |
| 2020-11-19 06:06:16 | <dsal> | @undo do { line <- getLine; putStrLn line } |
| 2020-11-19 06:06:16 | <lambdabot> | getLine >>= \ line -> putStrLn line |
| 2020-11-19 06:07:34 | <dsal> | How about this. Let's say you want to create a new thing called `getLines`. What does is its type? |
| 2020-11-19 06:07:40 | × | hidedagger quits (~nate@unaffiliated/hidedagger) (Quit: WeeChat 2.9) |
| 2020-11-19 06:07:49 | <n0042> | :t getLine |
| 2020-11-19 06:07:50 | <lambdabot> | IO String |
| 2020-11-19 06:07:57 | <n0042> | so... [IO String] ? |
| 2020-11-19 06:08:22 | <LKoen> | IO [String] ? |
| 2020-11-19 06:08:26 | <dsal> | That's not super useful, though, as you found out, because now instead of having one action, you have a list of actions. What would one action look like? |
| 2020-11-19 06:08:57 | → | xerox_ joins (~xerox@unaffiliated/xerox) |
| 2020-11-19 06:09:48 | <dsal> | So, there's a super easy way to go from `[m a]` to `m [a]` but I don't think it's necessarily a good path. It might be more useful for you to consider writing a function that takes the `n` and returns the actual thing you need. |
| 2020-11-19 06:10:24 | <dsal> | (which is technical `replicateM`, but you'd get pretty far along if you write this yourself) |
| 2020-11-19 06:10:29 | <n0042> | I must admit I'm having a hard time with Haskell's I/O. That is exactly what I'd like to do. |
| 2020-11-19 06:10:54 | <dsal> | You're having a hard time because you're trying to use it without understanding it or your goal. :) |
| 2020-11-19 06:10:59 | <n0042> | I have really enjoyed using this language for my assignments so far. It's a real pleasure to write and work with. |
| 2020-11-19 06:11:34 | → | borne joins (~fritjof@200116b864eda200f1dc39039d201adf.dip.versatel-1u1.de) |
| 2020-11-19 06:11:34 | <dsal> | It continues to get better as you learn more of it. But some things that you can kind of hand wave will eventually require a bit more understanding. In particular, expressing the type of the thing you want. |
| 2020-11-19 06:12:12 | → | SanchayanM joins (~Sanchayan@223.226.123.235) |
| 2020-11-19 06:12:57 | <n0042> | Well my goal is to take input, calculate some results, and print outputs. The "calculating some results" part is the actual assignment, and I've already worked it out, and was the fun part. The I/O part is throwing me for a loop because it should have been trivial. It's like two different languages when it comes to program logic and I/O |
| 2020-11-19 06:12:59 | <dsal> | Also, though it's still partial, I'd write what you have so far something like: `[bufferSize, numPackets] <- map read . words <$> getLine` -- but that's next week's episode. |
| 2020-11-19 06:13:16 | × | SanchayanMaity quits (~Sanchayan@106.201.35.233) (Ping timeout: 260 seconds) |
| 2020-11-19 06:13:39 | <n0042> | I am the sort of person who likes to understand this stuff from first principles where possible. Do you have any good resources for understanding how replicateM works on a more intuitive level? I'd like to learn this. |
| 2020-11-19 06:14:06 | <dsal> | Haskell Programming From First Principles will get you there quickly. |
| 2020-11-19 06:14:34 | <dsal> | @src replicateM |
| 2020-11-19 06:14:34 | <lambdabot> | replicateM n x = sequence (replicate n x) |
| 2020-11-19 06:14:49 | <zyklotomic> | the weird part about haskell is, the hard stuff becomes easy and the "easy" stuff becomes hard |
| 2020-11-19 06:14:55 | <zyklotomic> | *when you're first learning it |
| 2020-11-19 06:15:13 | <zyklotomic> | like IO basically |
| 2020-11-19 06:15:22 | <dsal> | I'd by that with the addendum. After a while, most things are easy. |
| 2020-11-19 06:15:51 | × | lukelau_ quits (~lukelau@46.101.13.214) (Quit: Bye) |
| 2020-11-19 06:16:05 | <n0042> | I recently joined a study group for that book, but we haven't started yet. |
| 2020-11-19 06:16:05 | <zyklotomic> | but i'm sure the fun never gets old |
| 2020-11-19 06:16:07 | → | lukelau joins (~lukelau@46.101.13.214) |
| 2020-11-19 06:16:25 | <n0042> | It really is a fun language. The list comprehensions are my favorite in any language I've used so far. |
| 2020-11-19 06:16:49 | <dsal> | I generally recommend that book. It's a slow path, which I think will get you somewhere useful the fastest. |
| 2020-11-19 06:17:19 | → | coot joins (~coot@37.30.49.253.nat.umts.dynamic.t-mobile.pl) |
| 2020-11-19 06:17:46 | → | darjeeling_ joins (~darjeelin@122.245.211.11) |
| 2020-11-19 06:17:46 | <zyklotomic> | list comprehensions are cool indeed |
| 2020-11-19 06:18:07 | <dsal> | I somehow don't use list comprehensions that much in haskell. |
| 2020-11-19 06:18:28 | <zyklotomic> | I use them in ghci most often tbh |
| 2020-11-19 06:18:31 | <dsal> | I often forget they exist. heh. |
| 2020-11-19 06:18:35 | <n0042> | So far everything I've written has been a mixture of list comprehensions and the recursive-go pattern. |
| 2020-11-19 06:18:42 | <n0042> | But I'm still doing pretty basic stuff |
| 2020-11-19 06:18:52 | <zyklotomic> | when I switched to Linux from a Mac, ghci replaced the Spotlight calculator if you know what spotlight is |
| 2020-11-19 06:18:59 | <n0042> | recursive-go makes my inner LISP programmer happy |
| 2020-11-19 06:19:07 | <zyklotomic> | basically just quickfire calculator that you can type some math into |
| 2020-11-19 06:19:07 | <dsal> | what's recursive-go? |
All times are in UTC.