Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,804,535 events total
2021-08-28 01:37:04 <dsal> I guess if you're going partial, you've also got `fmap read digitChar`
2021-08-28 01:37:26 <iqubic> Yeah, I suppose.
2021-08-28 01:37:54 <iqubic> But it's nice to have this as a megaparsec parser, so that I can put this into a much large parser later.
2021-08-28 01:38:10 × xff0x quits (~xff0x@2001:1a81:53dc:be00:a197:89df:f531:cbff) (Ping timeout: 240 seconds)
2021-08-28 01:38:18 <dsal> You can always just give that a name.
2021-08-28 01:38:40 <iqubic> But for my usecase this is entirely overkill. I'm just solving Advent Of Code 2017 Day 1 right now. https://adventofcode.com/2017/day/1
2021-08-28 01:39:04 <dsal> Oh, huh. I guess I've not done that year.
2021-08-28 01:40:14 xff0x joins (~xff0x@2001:1a81:5215:d000:44b2:e3e1:102e:1373)
2021-08-28 01:40:17 <iqubic> Basically part 1 is, given a large number, find all the digits such that the digit at position N matches the digit at position N + 1, and sum those.
2021-08-28 01:40:41 <iqubic> Assume the list is circular, so that the first digit comes right after the last one.
2021-08-28 01:41:27 <dsal> What type were you planning to use?
2021-08-28 01:41:28 <dsal> > digitToInt <$> "12345"
2021-08-28 01:41:29 <lambdabot> [1,2,3,4,5]
2021-08-28 01:41:43 <monochrom> "Num a" is the overkill.
2021-08-28 01:41:56 <iqubic> I was planning on using Int here.
2021-08-28 01:42:49 × MQ-17J quits (~MQ-17J@d14-69-206-129.try.wideopenwest.com) (Ping timeout: 252 seconds)
2021-08-28 01:43:06 MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com)
2021-08-28 01:43:18 <iqubic> Also, "pairs (x:xs) = let cyclic = xs ++ [x] in zip cyclic (tail cyclic)" is really powerful.
2021-08-28 01:43:53 × [itchyjunk] quits (~itchyjunk@user/itchyjunk/x-7353470) (Ping timeout: 250 seconds)
2021-08-28 01:44:18 <iqubic> Then I just mapMaybe to both turn pairs into single Ints and filter out the non-matching pairs. Then I sum that.
2021-08-28 01:46:32 falafel joins (~falafel@2600:100e:b144:da16:a499:a934:ae0d:b97)
2021-08-28 01:46:55 <hololeap> % :m + Text.Parsec
2021-08-28 01:46:55 <yahb> hololeap:
2021-08-28 01:46:58 <dsal> I don't quite understand why `pairs` is powerful there. It seems very specific.
2021-08-28 01:47:04 <hololeap> % :m + Text.Parsec.Char
2021-08-28 01:47:04 <yahb> hololeap:
2021-08-28 01:47:11 <hololeap> % parseDigits = fmap (fmap (read . pure)) (Text.Parsec.many digit)
2021-08-28 01:47:11 <yahb> hololeap:
2021-08-28 01:47:17 <hololeap> % parseTest (parseDigits :: Parsec String () [Int]) "243439102"
2021-08-28 01:47:18 <yahb> hololeap: [2,4,3,4,3,9,1,0,2]
2021-08-28 01:47:23 <hololeap> iqubic: ^ ?
2021-08-28 01:47:43 × alx741 quits (~alx741@181.196.68.187) (Quit: alx741)
2021-08-28 01:47:56 [itchyjunk] joins (~itchyjunk@user/itchyjunk/x-7353470)
2021-08-28 01:53:25 × MQ-17J quits (~MQ-17J@d14-69-206-129.try.wideopenwest.com) (Ping timeout: 250 seconds)
2021-08-28 01:53:42 MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com)
2021-08-28 01:54:09 <iqubic> hololeap, yes that.
2021-08-28 01:54:21 <iqubic> Why are you fmaping twice?
2021-08-28 01:54:37 aplainzetakind joins (~johndoe@captainludd.powered.by.lunarbnc.net)
2021-08-28 01:54:55 <dsal> It's reading the result of a parse inside of the parser.
2021-08-28 01:55:09 <hololeap> because it's operating on `Parsec [Char]` , so there are two functors to get up through to operate on the Char
2021-08-28 01:55:13 × azeem quits (~azeem@5.168.221.147) (Ping timeout: 248 seconds)
2021-08-28 01:55:27 azeem joins (~azeem@5.168.221.147)
2021-08-28 01:56:00 <hololeap> the `pure` turns that Char into [Char] (aka String)
2021-08-28 01:56:01 × zaquest quits (~notzaques@5.128.210.178) (Remote host closed the connection)
2021-08-28 01:56:10 <hololeap> and then it gets read
2021-08-28 01:57:08 <hololeap> I could have also written it: fmap (map (read . pure))
2021-08-28 01:57:39 <hololeap> or: fmap (map (read . ( \x -> [x] ) ))
2021-08-28 01:59:17 <iqubic> Ah. I see. Makes sense.
2021-08-28 02:00:25 <dsal> Oh weird. I apparently have stars on this, but I have no idea where my code went.
2021-08-28 02:01:01 chris joins (~chris@81.96.113.213)
2021-08-28 02:01:04 chris is now known as Guest9286
2021-08-28 02:01:39 zaquest joins (~notzaques@5.128.210.178)
2021-08-28 02:03:45 <hololeap> iqubic: so right after the `pure` the type would be `Parsec http://en.wikipedia.org/wiki/Special:Search?go=Go&search=Char` aka `Parsec [String]`, and then the `read` inside the map turns this into `Read a => Parsec [a]`
2021-08-28 02:04:01 <hololeap> that was weird
2021-08-28 02:04:29 <hololeap> * double-list of Char
2021-08-28 02:05:10 hololeap turns off "auto-replace" "feature" in the IRC client
2021-08-28 02:05:22 × Pent quits (sid313808@id-313808.tooting.irccloud.com) (Ping timeout: 256 seconds)
2021-08-28 02:05:28 <monochrom> Type-level URLs!
2021-08-28 02:05:36 <hololeap> lol
2021-08-28 02:06:14 × gonz__ quits (sid304396@id-304396.tooting.irccloud.com) (Ping timeout: 258 seconds)
2021-08-28 02:07:21 <iqubic> Anyways, mapMaybe is an excellent list function. Does there exist such a function that works on all Foldables, or would that not really make sense?
2021-08-28 02:07:21 Pent joins (sid313808@id-313808.tooting.irccloud.com)
2021-08-28 02:07:23 <hololeap> *so right after the `pure` the type would be `Parsec [[Char]]` aka `Parsec [String]`, and then the `read` inside the map turns this into `Read a => Parsec [a]`
2021-08-28 02:07:34 <hololeap> iqubic: witherable
2021-08-28 02:07:38 × hendi quits (sid489601@id-489601.tooting.irccloud.com) (Ping timeout: 256 seconds)
2021-08-28 02:07:53 gonz__ joins (sid304396@tooting.irccloud.com)
2021-08-28 02:08:10 × MQ-17J quits (~MQ-17J@d14-69-206-129.try.wideopenwest.com) (Ping timeout: 240 seconds)
2021-08-28 02:08:12 × Adeon quits (sid418992@id-418992.tooting.irccloud.com) (Ping timeout: 256 seconds)
2021-08-28 02:08:13 <iqubic> But after the pure, you just get a list of strings of length 1. Is that really what you need in order to make the call to read typecheck?
2021-08-28 02:09:20 × christiaanb quits (sid84827@id-84827.tooting.irccloud.com) (Ping timeout: 256 seconds)
2021-08-28 02:09:37 <hololeap> it always typechecks... because it's partial. it will throw a pure error if it doesn't read, and we're depending on parsec to give it something that it can
2021-08-28 02:10:14 × Pent quits (sid313808@id-313808.tooting.irccloud.com) (Max SendQ exceeded)
2021-08-28 02:10:22 hendi joins (sid489601@id-489601.tooting.irccloud.com)
2021-08-28 02:10:58 Pent joins (sid313808@id-313808.tooting.irccloud.com)
2021-08-28 02:11:02 MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com)
2021-08-28 02:11:04 × nrr quits (sid20938@id-20938.tooting.irccloud.com) (Ping timeout: 250 seconds)
2021-08-28 02:11:46 christiaanb joins (sid84827@tooting.irccloud.com)
2021-08-28 02:12:00 × adamse quits (sid72084@user/adamse) (Ping timeout: 272 seconds)
2021-08-28 02:12:06 Adeon joins (sid418992@id-418992.tooting.irccloud.com)
2021-08-28 02:12:12 <hololeap> @hoogle Witherable
2021-08-28 02:12:12 <lambdabot> Data.Witherable.Class class (Traversable t, Filterable t) => Witherable t
2021-08-28 02:12:12 <lambdabot> package witherable
2021-08-28 02:12:12 <lambdabot> package witherable-class
2021-08-28 02:12:28 × hsiktas quits (sid224847@tooting.irccloud.com) (Ping timeout: 268 seconds)
2021-08-28 02:12:38 <hololeap> iqubic: ^ -- in regards to your second question about mapMaybe
2021-08-28 02:13:21 × MQ-17J quits (~MQ-17J@d14-69-206-129.try.wideopenwest.com) (Read error: Connection reset by peer)
2021-08-28 02:13:43 <dsal> :t read
2021-08-28 02:13:44 <lambdabot> Read a => String -> a
2021-08-28 02:14:01 MQ-17J joins (~MQ-17J@8.6.144.209)
2021-08-28 02:14:40 × PotatoGim quits (sid99505@tooting.irccloud.com) (Ping timeout: 258 seconds)
2021-08-28 02:14:43 adamse joins (sid72084@user/adamse)
2021-08-28 02:14:53 <hololeap> pure error meaning a runtime error that can't be caught, e.g. `head []`
2021-08-28 02:15:01 hsiktas joins (sid224847@id-224847.tooting.irccloud.com)
2021-08-28 02:15:02 <hololeap> (or maybe you can in IO somehow... can't remember)
2021-08-28 02:15:59 nrr joins (sid20938@id-20938.tooting.irccloud.com)
2021-08-28 02:16:36 <Cale> You can, but you definitely don't want to be forced to. I'd sooner fork a library than try to catch an exception it's throwing from evaluation.
2021-08-28 02:16:55 × FinnElija quits (~finn_elij@user/finn-elija/x-0085643) (Ping timeout: 252 seconds)
2021-08-28 02:17:50 <hololeap> I think that calling `read` here is safe because the input is coming from parsec's `digit`
2021-08-28 02:17:52 × elf_fortrez quits (~elf_fortr@adsl-72-50-4-145.prtc.net) (Ping timeout: 246 seconds)
2021-08-28 02:18:51 <Cale> if the list is nonempty

All times are in UTC.