Code Monkey home page Code Monkey logo

Comments (3)

sorki avatar sorki commented on September 17, 2024

Hi, sounds good to me but to be honest, I'm not sure how to convert it to tagless final right away. If you have good example I can take a look at or draft a solution here it would help a lot.

Regarding breaking the API - I don't think there are that many users of this library so it should be fine.

from blockfrost-haskell.

sorki avatar sorki commented on September 17, 2024

I've remembered about https://jproyo.github.io/posts/2019-03-17-tagless-final-haskell.html and it makes sense, having a typeclass BlockfrostClient (or maybe just Blockfrost to avoid name clashes) with instance that can possibly call the fixed mtl client functions. What I'm not sure about is ReaderT containing Project, maybe we can just wrap our old BlockfrostClient type though. I'll play with it a bit!

from blockfrost-haskell.

sorki avatar sorki commented on September 17, 2024

Hi, I've opened #11 which adds MonadBlockfrost class allowing you to use a custom monad instead of the default BlockfrostClient.

Using this I was able to compose it with example TestapiM like this:

class Monad m => TestapiM m where
  mGetTest :: m Bool

sample :: (MonadBlockfrost m, TestapiM m) => m ()
sample = pure ()

type GlobalConfig = (Bool, ClientConfig)
type App = ReaderT GlobalConfig (ExceptT ClientError IO)

runApp :: ClientConfig -> App a -> IO (Either ClientError a)
runApp globalC = runExceptT . flip runReaderT (True, globalC)

instance TestapiM App where
  mGetTest = fst <$> ask

instance MonadBlockfrost App where
  liftBlockfrostClient act = getConf >>= \(env, _prj) -> 
    (liftIO $ runClientM act env)
  getConf = snd <$> ask

Would this work for you?

from blockfrost-haskell.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.