Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-05-04 10:54:34 royal_screwup213 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-05-04 10:54:54 tsteeples joins (~steeps@cpc121168-oxfd27-2-0-cust161.4-3.cable.virginm.net)
2021-05-04 10:58:12 philderbeast joins (~textual@bras-base-vldvpq5901w-grc-06-184-144-244-252.dsl.bell.ca)
2021-05-04 10:58:38 × cads quits (~cads@ip-64-72-99-232.lasvegas.net) (Read error: Connection reset by peer)
2021-05-04 10:59:25 × royal_screwup213 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Ping timeout: 252 seconds)
2021-05-04 10:59:28 × ukari quits (~ukari@unaffiliated/ukari) (Remote host closed the connection)
2021-05-04 10:59:43 ukari joins (~ukari@unaffiliated/ukari)
2021-05-04 10:59:52 × raym quits (~ray@45.64.220.116) (Ping timeout: 240 seconds)
2021-05-04 11:02:40 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Quit: leaving)
2021-05-04 11:02:43 × geowiesnot quits (~user@87-89-181-157.abo.bbox.fr) (Ping timeout: 252 seconds)
2021-05-04 11:03:45 <tsteeples> Hi all - recently started getting back into Haskell, and having trouble understanding what the best way to approach a certain problem is. I have an fixed sqlite database, from which I need to read only (no writing). Naturally, I'm trying to keep pure and IO functionality separate, but some of my "atomic" operations do require access to the database (I'm essentially using it as a lookup table). Thus it seems that all
2021-05-04 11:03:46 <tsteeples> my code will become fairly inextricably tied into the IO monad. Is there a better pattern for this, or just something I have to suck up? In the grand scheme of things, the database isn't large at all (2MB), so it is somewhat possible to just embed the data straight into code, but I can't imagine that's anything resembling best practice. Does anyone have any good suggestions/any patterns that I'm not aware of? Cheers
2021-05-04 11:03:46 <tsteeples> in advance.
2021-05-04 11:05:01 × esp32_prog quits (~esp32_pro@89.45.7.186) (Remote host closed the connection)
2021-05-04 11:05:18 <cub3s_> tsteeples, you could read that 2MB data into memory (as a neat data structure) and just use it purely from then on
2021-05-04 11:05:27 royal_screwup213 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-05-04 11:05:50 × Guest52589 quits (~textual@zrcout.mskcc.org) (Quit: Textual IRC Client: www.textualapp.com)
2021-05-04 11:06:26 merijn joins (~merijn@83-160-49-249.ip.xs4all.nl)
2021-05-04 11:06:29 <chisui> tsteeples you could create a class for your database actions and let `IO` implement that class. This makes it possible to also have a pure implementation for testing.
2021-05-04 11:07:03 <chisui> something like `class Db m where readValue :: String -> m String`
2021-05-04 11:07:39 <tsteeples> cub3s_... I'm an idiot. Yeah, that's perfect, I'll do that.
2021-05-04 11:07:55 EvilMagix joins (~aVikingTr@2001:8003:340d:d00:b2de:b98:7a93:b0ea)
2021-05-04 11:07:58 <merijn> I never understood the "pure implementation" for testing approach to DB interaction
2021-05-04 11:08:12 <tsteeples> chisui - ok, so what advantage would that offer over just doing everything through the IO monad?
2021-05-04 11:08:22 <merijn> Like, I need my code to work with an *actual* database, not a hypothetical one
2021-05-04 11:08:43 <merijn> tsteeples: Allows you to refactor DB logic independent from the rest of your code
2021-05-04 11:08:59 <maerwald> merijn: theoretically separating types of bugs... you would still run it against an actual DB as well
2021-05-04 11:09:12 <maerwald> it has its merits
2021-05-04 11:09:24 <merijn> maerwald: Right, so it just sounds like "more work" in the case of databases
2021-05-04 11:09:28 <chisui> tsteeples code that operates on the abstraction does not have the full power of `IO`.
2021-05-04 11:09:29 <maerwald> yes
2021-05-04 11:09:44 <merijn> tsteeples: I probably wouldn't go the "readValue" approach described earlie
2021-05-04 11:10:06 <merijn> tsteeples: What I'm using myself now (that I'm fairly happy with) is: https://github.com/merijn/Belewitte/blob/master/benchmark-analysis/src/Sql/Core.hs#L130-L133
2021-05-04 11:10:35 × royal_screwup213 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-05-04 11:10:48 <tsteeples> merijn: Ah cool, ok, I'll take a look
2021-05-04 11:10:54 royal_screwup213 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-05-04 11:11:19 <tsteeples> merijn: Looks neat, cheers all!
2021-05-04 11:11:28 <merijn> tsteeples: All my actual queries use that class to grab a connection, which means my database operations can only rely on "there is a connection we can do stuff on" and can't accidentally rely on the rest of my code
2021-05-04 11:11:36 <chisui> merijn in most cases I wouldn't abstract the DB access itself into a class but rather functions to access processed data. Kind of like an equivalent to the OOP DAO pattern.
2021-05-04 11:11:46 <merijn> tsteeples: Which in turn means it's easy to adapt/reuse my database code in different settings
2021-05-04 11:13:03 × kadoban quits (~mud@unaffiliated/kadoban) (Quit: bye)
2021-05-04 11:13:13 <cub3s_> Is Nixpkgs (non-broken packages) analogous to a Stack resolver?
2021-05-04 11:13:45 <merijn> tsteeples: I'm growing quite fond of the "have a very tiny set of core primitives in a class, implement the full API on top of that" approach. It enforces decoupling which makes it easier to refactor things later
2021-05-04 11:13:50 <chisui> in tsteeples case I would also just read the db on startup
2021-05-04 11:14:16 <merijn> tsteeples: For example, since the db code only relies on those 3 primitives in the class, any refactor can never require more work than fixing those 3 things
2021-05-04 11:14:29 <merijn> Which is generally fairly trivial
2021-05-04 11:14:48 <merijn> I missed the initial question, so I dunno :p
2021-05-04 11:15:11 × royal_screwup213 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Ping timeout: 240 seconds)
2021-05-04 11:15:14 <Taneb> cub3s_: I think it's currently based on a recent stackage nightly
2021-05-04 11:16:22 ValeraRozuvan joins (~ValeraRoz@95.164.65.159)
2021-05-04 11:17:40 <cub3s_> Taneb, yes but it does have all hackage packages that are not in stackage (although ones i've seen so far happen to be marked as broken)
2021-05-04 11:18:04 <cub3s_> has anyone written something about stack vs. nixpkgs that answers such questions?
2021-05-04 11:18:18 <merijn> Probably
2021-05-04 11:18:48 <merijn> There seems to be and endless supply of nixpkg propaganda on blogs >.>
2021-05-04 11:19:06 machinedgod joins (~machinedg@135-23-192-217.cpe.pppoe.ca)
2021-05-04 11:19:14 <cub3s_> merijn, what do you mean propaganda
2021-05-04 11:19:45 <maerwald> sunk cost fallacy
2021-05-04 11:19:54 <Arahael> Learning nix is *hard*.
2021-05-04 11:20:03 <Arahael> I still haven't learnt it.
2021-05-04 11:20:03 <maerwald> you spent 3 years figuring out nix, now you gotta use it for everything and say it's great
2021-05-04 11:20:34 <merijn> cub3s_: "propaganda, noun, information, especially of a biased or misleading nature, used to promote a political cause or point of view."
2021-05-04 11:20:40 <merijn> cub3s_: Seems accurate enough :)
2021-05-04 11:20:45 <Arahael> I find the nix language weird, but it doesn't help that it's a bona-fide language, and the way you use it to configure larger projects seems... Random.
2021-05-04 11:20:49 <merijn> Don't get me wrong, I like nix *in theory*
2021-05-04 11:20:55 <Arahael> I love nix in theory.
2021-05-04 11:20:58 <merijn> I just hate nix *in practice*
2021-05-04 11:21:08 <Arahael> I regret running nix on my (personal) server.
2021-05-04 11:21:23 <cub3s_> what are the biggest issues with it?
2021-05-04 11:21:29 <Arahael> I think I'd have been far better off just installing debian, and maybe using nix for a couple of rnadom projects.
2021-05-04 11:21:35 <merijn> cub3s_: There's lots of blog posts espousing how Nix will solve all your problems, but I find it very painful to use
2021-05-04 11:21:36 <maerwald> cub3s_: figuring out how it works :D
2021-05-04 11:21:41 × plutoniix quits (~q@ppp-171-97-97-6.revip8.asianet.co.th) (Quit: Leaving)
2021-05-04 11:21:57 <Arahael> cub3s_: Nix is, frankly, little more than a huge, huge program with a whole lot of code.
2021-05-04 11:21:57 <merijn> cub3s_: The language is entirely undocumented, errors opaque/impossible, getting it configured to work is a massive PITA
2021-05-04 11:22:07 <Arahael> Oh, the language is slightly documented.
2021-05-04 11:22:12 <hc> that sums up my (brief) experience with it :)
2021-05-04 11:22:18 <merijn> cub3s_: Like, I'm sure that if someone has a curated setup you can use, it works great
2021-05-04 11:22:34 <merijn> But if you don't have a nix expert on hand, be prepared to spend days getting it working :p
2021-05-04 11:22:53 <merijn> Meanwhile v2-build gives me, like, 80-90% of the benefit for 5% of the work :p
2021-05-04 11:23:23 <maerwald> static binaries, forget nix
2021-05-04 11:23:47 <Arahael> I still don't know how to use nix with a project. Do I have .nix files in teh repo, or keep it separate? How do I refer to the actual nix tree, etc.
2021-05-04 11:24:03 <cub3s_> i thought nixpkgs (or stack resolver) was supposed to provide curated package sets, thus adding to cabal
2021-05-04 11:24:05 <maerwald> although if your project is composed of several binaries (like blockchains)... static alone isn't enough
2021-05-04 11:24:12 Alleria joins (~textual@zrcout.mskcc.org)
2021-05-04 11:24:23 <merijn> maerwald: Oh, my one conclusion from my career so far, especially in science is: https://i.imgflip.com/586wyo.jpg
2021-05-04 11:24:26 × texasmynsted quits (~texasmyns@99.96.221.112) (Ping timeout: 260 seconds)
2021-05-04 11:24:36 <maerwald> so cardanos daedalus uses nix under the hood to start up node/wallet etc
2021-05-04 11:24:36 Alleria is now known as Guest69224
2021-05-04 11:24:37 <Arahael> That said, a nix-ified project is pretty nice to get into. nix-shell -p, and you're in an environment that's already setup to dev in it.
2021-05-04 11:24:51 <maerwald> I can see how that is actually a good use case
2021-05-04 11:25:04 <maerwald> but I don't envy the people maintaining it
2021-05-04 11:25:15 texasmynsted joins (~texasmyns@99.96.221.112)
2021-05-04 11:25:22 <merijn> cub3s_: Well, that depends on how you value the curation (and what you expect that to entail)
2021-05-04 11:26:01 <cub3s_> merijn, maybe the fact is you don't encounter dependency hell that often in practice?
2021-05-04 11:26:05 <merijn> I mean, stack curation is mostly "check things build and run some of the tests"
2021-05-04 11:26:26 <merijn> cub3s_: v2-build has eliminated most of my pain wrt dependencies
2021-05-04 11:26:30 <cub3s_> (or maybe even the existence of stack/nixpkgs have themselves motivated devs to remove such dependency hells to begin with, leading to cabal being useful on its own??)
2021-05-04 11:26:32 <Arahael> I have dependency hell at work. :(
2021-05-04 11:26:48 <Arahael> merijn: Oh, today I made PROGRESS! :D I compiled half my project in xcode 12.5 :D
2021-05-04 11:26:49 <merijn> cub3s_: Most of the remaining issues with v2-build are just "trying to use bit-rotted packages"

All times are in UTC.