I'm writing my first greenfield project in Haskell having been tinkering for quite a while. It's become apparent that I don't have a good intuition for "haskell in the large" (and this is a feeling I've seen expressed before by people new to the language). If it's OK I'd like to ask some general big picture haskell application design questions here in the hope that they will help myself and others.
Here's what I'm writing for some context:
I want to write a client library for my excellent online small business accounting package, freeagent (which is an oauth2 web service). Eventually I'd like to make it into a bridging library between freeagent and hledger. I'll need the following:
Oauth2 library and http client. I've gone for hoauth2 and http-streams. I'm not set in stone here; any pointers?
A library to manage a ~/.hfreeagent config file. The config file will need to manage and store the oauth credentials (id, secret, hostname etc), the location of ledger files, and token management (oauth2 tokens need to be periodically refreshed). ConfigFile or bos' library look like good options here.
A rest client which marshals json objects to haskell and thence to however hledger represents things. Aeson looks good for this one.
So far so good!
So the questions then:
What should my monad stack look like? The presence of the config suggests a ReaderT somewhere. But I'll also need to write to the config file when I refresh a token, so do I need StateT? Or do I need two separate interfaces? I understand monads and transformers, but I now realise that I have no idea how to design them.
Any pointers on structuring the library (directory structure, module naming etc).
Is there anything that could generate my types from json for me? Something like F#'s type providers, template haskell or some clever lensing. Or do I have to go and manually define all of the types in the API that I want to use: https://dev.freeagent.com/docs?
How would you model the workflow of looking up the token, checking if it's still valid, refreshing it if not and then making it available to the rest client? (this goes back to the monad question I guess).
I think that will do for now. The library will be open source https://github.com/perurbis/hfreeagent, and I'd like for it to serve as a roadmap if possible for folks moving from playing with and liking Haskell to actually thinking about and building real world stuff with it. This is the reason I'm asking here, rather than SO so people can follow along - and it doesn't get closed as too general :-). I will attempt to roll all of the good stuff from the conversation here - if any into the documentation.
Thanks all, Bensubmitted by b00thead
[link] [23 comments]
I'm trying to find my way around Template Haskell, so after discovering that all the liftA* functions can be built from just pure and <*> like this:fp a b = a . <*> . b liftA = fp id pure liftA2 = (fp . fp) id pure liftA3 = (fp . fp . fp) id pure
et cetera, I decided to make a liftA* function generator in template haskell. The code is here - it defines functions named liftA', liftA2', etc.
I found it difficult to figure out when to use functions like varT, appT, etc., and when to use the data constructors VarT, AppT, etc. The version I have now almost exclusively uses the lowercase functions that operate inside the Q monad but my code went through several iterations to get there and I'm not sure that's the right choice.
I'd appreciate people with TH experience taking a look and commenting on my approach to the extent that it's possible to do so with such a small code sample.submitted by fizbin
[link] [2 comments]
I'm curious to know what the most common approach to concurrency is. Do you:
- Use threads with MVars for synchronizing and passing data?
- Use Software Transactional Memory (STM)?
- Use event-based concurrency?
- Use some library that implements Actors?
- Use Cloud Haskell?
- Something else entirely?
[link] [29 comments]
I believe I read the post in this subreddit, and it was a recent post from the front page as well, but I cannot find either the post or the thread that contained it, and it was an incredibly useful comment.
I was going to show it to some more people today, but couldn't find the link.
The comment compared the metaprogramming facilities in lisp to that of haskell.
Template Haskell was mentioned as well as 4 or 5 other specifications about how haskell can accomplish already most of the use cases of lisp macros.
The post concluded that Haskell either already can or is headed in the direction of accomplishing every use case except for one, and the use case was one that was very generic to lisp.
The post was neutral in tone and written in a detailed manner.
It was about a page long iirc and used parentheses around every digit corresponding to each use case for the lisp facilities.
I think it had a score of around 20 or 30 at the time I read it, but I am more fuzzy on that point.
It was in exchange with a more lisp centric individual who was also neutral in tone in the responses.
Searching the subreddit for posts or threads that included template haskell and macros or lisp macros or metaprogramming did not turn up what I am looking for.
I would be really appreciative for any help locating this as it was the best info I've seen on the topic.submitted by MoreHugs
[link] [3 comments]