Logs: freenode/#haskell
| 2020-10-12 01:24:55 | × | st8less quits (~st8less@2603:a060:11fd:0:9c66:9b18:c21:60c) (Ping timeout: 244 seconds) |
| 2020-10-12 01:26:28 | × | raehik quits (~raehik@cpc96984-rdng25-2-0-cust109.15-3.cable.virginm.net) (Ping timeout: 244 seconds) |
| 2020-10-12 01:26:45 | × | xerox_ quits (~xerox@unaffiliated/xerox) (Ping timeout: 240 seconds) |
| 2020-10-12 01:26:48 | × | snakemas1 quits (~snakemast@213.100.206.23) (Ping timeout: 260 seconds) |
| 2020-10-12 01:27:04 | <proofofme> | it's installing successfully so far :) |
| 2020-10-12 01:28:04 | <cohn> | I'm playing around with the Text.CSV module. Hopefully this is an easy one: how can I get the "head" of the CSV data (the column names)? |
| 2020-10-12 01:28:15 | <cohn> | when I do this: dat <- parseCSVFromFile "foo.csv" |
| 2020-10-12 01:28:28 | <cohn> | the result has this type: dat :: Either parsec-3.1.14.0:Text.Parsec.Error.ParseError CSV |
| 2020-10-12 01:28:48 | → | st8less joins (~st8less@2603:a060:11fd:0:9c66:9b18:c21:60c) |
| 2020-10-12 01:28:55 | <cohn> | so it's wrapped in an "Either"... just need to get the Right value. |
| 2020-10-12 01:29:19 | → | olligobber joins (olligobber@gateway/vpn/privateinternetaccess/olligobber) |
| 2020-10-12 01:31:21 | → | aaaaaa joins (~ArthurStr@host-91-90-11-13.soborka.net) |
| 2020-10-12 01:31:23 | <proofofme> | pattern matching and `case` is my best guess. I'm pretty novice though ... |
| 2020-10-12 01:32:33 | <proofofme> | https://stackoverflow.com/questions/46944347/how-to-get-value-from-either Does this help? |
| 2020-10-12 01:33:05 | <cohn> | yep, thanks proofofme! |
| 2020-10-12 01:33:57 | → | ensyde joins (~ensyde@2600:1702:2e30:1a40:9170:421:4d7b:753d) |
| 2020-10-12 01:34:47 | → | conal joins (~conal@64.71.133.70) |
| 2020-10-12 01:34:50 | <proofofme> | apparently, you can use `fromRight` as well, but that can come with some issues, if not accounted for. I used `fromJust` to unwrap a Maybe from an IO monad to get to the [String] beneath yesterday. Took some time to figure it out lol |
| 2020-10-12 01:34:57 | × | olligobber quits (olligobber@gateway/vpn/privateinternetaccess/olligobber) (Ping timeout: 258 seconds) |
| 2020-10-12 01:35:03 | × | polyrain quits (~polyrain@2001:8003:e501:6901:1d4a:4b8a:8ea1:adc0) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2020-10-12 01:37:55 | → | vonfry joins (~user@li1870-189.members.linode.com) |
| 2020-10-12 01:38:17 | <ski> | proofofme : probably better to handle the error case explicitly .. unless maybe if you're really sure it can't happen |
| 2020-10-12 01:38:45 | → | wroathe_ joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) |
| 2020-10-12 01:39:01 | <ski> | (but even then, it can be better to have an explicit pattern-match, rather than `fromJust',`fromRight',`head',`tail', since with those, you don't get a location if things go south) |
| 2020-10-12 01:39:05 | × | wroathe quits (~wroathe@c-73-24-27-54.hsd1.mn.comcast.net) (Ping timeout: 240 seconds) |
| 2020-10-12 01:39:19 | <cohn> | crikey... not woring |
| 2020-10-12 01:39:22 | <proofofme> | so you would use `case` and pattern matching for that just by default, yeah? |
| 2020-10-12 01:39:23 | <cohn> | *working |
| 2020-10-12 01:40:24 | <proofofme> | cohn, let me see if I can get the same thing working on my end |
| 2020-10-12 01:40:42 | × | Gurkenglas quits (~Gurkengla@unaffiliated/gurkenglas) (Ping timeout: 265 seconds) |
| 2020-10-12 01:41:05 | × | CMCDragonkai1 quits (~Thunderbi@124.19.3.250) (Ping timeout: 240 seconds) |
| 2020-10-12 01:41:14 | <ski> | proofofme : you could use `Right x = ...' in a `let' or where. or apply `\(Right x) -> x' to the result |
| 2020-10-12 01:41:28 | × | aaaaaa quits (~ArthurStr@host-91-90-11-13.soborka.net) (Ping timeout: 258 seconds) |
| 2020-10-12 01:41:33 | <cohn> | for the curious: https://pastebin.com/MYixX2vp |
| 2020-10-12 01:42:08 | → | aaaaaa joins (~ArthurStr@host-91-90-11-13.soborka.net) |
| 2020-10-12 01:43:46 | <cohn> | this is what frustrates me about Haskell. It's easy to pick up the basics of the language but when it comes time to use library modules, it's a PITA. |
| 2020-10-12 01:44:14 | <proofofme> | what is `dat`? |
| 2020-10-12 01:44:23 | <lemmih> | cohn: Your problem is with static typing, though, not libraries. |
| 2020-10-12 01:44:28 | hackage | churros 0.1.0.3 - Channel/Arrow based streaming computation library. https://hackage.haskell.org/package/churros-0.1.0.3 (LyndonMaydwell) |
| 2020-10-12 01:45:04 | <lemmih> | cohn: What's the type of your expression? |
| 2020-10-12 01:45:18 | <cohn> | proofofme: it's the result of reading the CSV file |
| 2020-10-12 01:45:25 | <cohn> | https://hackage.haskell.org/package/csv-0.1.2/docs/Text-CSV.html |
| 2020-10-12 01:45:26 | <proofofme> | ah |
| 2020-10-12 01:45:37 | <cohn> | lemmih: I would agree |
| 2020-10-12 01:45:43 | <ski> | cohn : probably `head d' doesn't have type `String' |
| 2020-10-12 01:46:24 | <lemmih> | cohn: Static typing is not optional in Haskell. You just gotta bite the bullet and always keep types in mind. |
| 2020-10-12 01:46:39 | <jchia> | Why is there a head fold but no 'tail' in Control.Foldl? Is a tail old that hard to define properly? |
| 2020-10-12 01:46:45 | <ski> | cohn : do you know what you want to happen/do, in the error case ? |
| 2020-10-12 01:46:59 | <cohn> | so, `dat <- parseCSVFromFile "foo.csv"` |
| 2020-10-12 01:47:14 | <cohn> | ski: just print an error message. |
| 2020-10-12 01:47:20 | <ski> | what is `CSV' ? |
| 2020-10-12 01:47:27 | <ski> | a type synonym ? |
| 2020-10-12 01:47:31 | → | olligobber joins (olligobber@gateway/vpn/privateinternetaccess/olligobber) |
| 2020-10-12 01:47:38 | × | aaaaaa quits (~ArthurStr@host-91-90-11-13.soborka.net) (Ping timeout: 256 seconds) |
| 2020-10-12 01:47:39 | <cohn> | yes |
| 2020-10-12 01:47:45 | <ski> | cohn : and abort the program, or not ? |
| 2020-10-12 01:47:48 | <lemmih> | type CSV = [[String]] |
| 2020-10-12 01:47:51 | <ski> | ok |
| 2020-10-12 01:48:15 | <cohn> | ski: I'm playing around in GHCi, so no need to exit. : ) |
| 2020-10-12 01:48:17 | → | _vaibhavingale_ joins (~Adium@203.188.228.27) |
| 2020-10-12 01:48:17 | × | GyroW_ quits (~GyroW@unaffiliated/gyrow) (Quit: Someone ate my pie) |
| 2020-10-12 01:48:28 | → | GyroW joins (~GyroW@d54c03e98.access.telenet.be) |
| 2020-10-12 01:48:29 | × | GyroW quits (~GyroW@d54c03e98.access.telenet.be) (Changing host) |
| 2020-10-12 01:48:29 | → | GyroW joins (~GyroW@unaffiliated/gyrow) |
| 2020-10-12 01:48:57 | <ski> | cohn : yes, but i'm asking you what you want your program to do, when there's a parse error |
| 2020-10-12 01:49:09 | <cohn> | just print an error message |
| 2020-10-12 01:49:11 | <ski> | should it continue processing, somehow ? |
| 2020-10-12 01:49:13 | <ski> | or just stop ? |
| 2020-10-12 01:49:24 | <cohn> | yes, just stop and print an error message |
| 2020-10-12 01:49:27 | → | polyrain joins (~polyrain@2001:8003:e501:6901:1d4a:4b8a:8ea1:adc0) |
| 2020-10-12 01:49:39 | <ski> | then call `error' in the `Left' parameter case for `either' |
| 2020-10-12 01:50:02 | <ski> | (that will also fix this type mismatch error) |
| 2020-10-12 01:50:18 | → | _vaibhavingale_1 joins (~Adium@203.188.228.27) |
| 2020-10-12 01:50:36 | <cohn> | whoa! that worked! thanks, ski! |
| 2020-10-12 01:50:37 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 264 seconds) |
| 2020-10-12 01:50:43 | <ski> | because |
| 2020-10-12 01:50:47 | <ski> | @type error |
| 2020-10-12 01:50:48 | <lambdabot> | [Char] -> a |
| 2020-10-12 01:51:03 | <ski> | `error' promises that its return value will be of any type `a' that the caller would like |
| 2020-10-12 01:51:21 | <ski> | (this works, because `error' doesn't return a value, instead it aborts computation) |
| 2020-10-12 01:52:00 | <ski> | cohn : btw, you can simplify ("eta-reduce") `\d -> head d', to just `head' |
| 2020-10-12 01:52:01 | <cohn> | ah, okay. so because I didn't use `error`, the computation didn't abort, which caused the type mismatch message in my paste? |
| 2020-10-12 01:52:13 | <ski> | (but possibly you want to put more code into that alternative ..) |
| 2020-10-12 01:52:16 | → | _vaibhavingale_2 joins (~Adium@203.188.228.27) |
| 2020-10-12 01:52:19 | <ski> | yes, cohn |
| 2020-10-12 01:52:25 | × | olligobber quits (olligobber@gateway/vpn/privateinternetaccess/olligobber) (Ping timeout: 240 seconds) |
| 2020-10-12 01:52:39 | <ski> | it tried to check that the result type of both "branches" was the same .. and they weren't |
| 2020-10-12 01:52:47 | × | _vaibhavingale_ quits (~Adium@203.188.228.27) (Ping timeout: 265 seconds) |
| 2020-10-12 01:53:12 | <cohn> | ok, so... |
| 2020-10-12 01:53:16 | <cohn> | @type either |
| 2020-10-12 01:53:18 | <lambdabot> | (a -> c) -> (b -> c) -> Either a b -> c |
| 2020-10-12 01:53:35 | <cohn> | so the type of 'c' was different? |
| 2020-10-12 01:53:45 | → | ttc joins (tomtauma1@gateway/shell/matrix.org/x-dyilsezwqgixpwcl) |
| 2020-10-12 01:53:47 | × | polyrain quits (~polyrain@2001:8003:e501:6901:1d4a:4b8a:8ea1:adc0) (Client Quit) |
| 2020-10-12 01:54:12 | × | _vaibhavingale_2 quits (~Adium@203.188.228.27) (Read error: Connection reset by peer) |
| 2020-10-12 01:54:15 | → | _vaibhavingale_ joins (~Adium@203.188.228.27) |
| 2020-10-12 01:54:35 | × | hiptobecubic quits (~john@unaffiliated/hiptobecubic) (Remote host closed the connection) |
| 2020-10-12 01:54:43 | × | _vaibhavingale_1 quits (~Adium@203.188.228.27) (Ping timeout: 265 seconds) |
| 2020-10-12 01:55:09 | × | _vaibhavingale_ quits (~Adium@203.188.228.27) (Read error: Connection reset by peer) |
| 2020-10-12 01:55:11 | <cohn> | and yes, it works with eta reduction: `either (\err -> error "Didn't work") head dat` |
All times are in UTC.