haskell-servant / haskell-servant/servant

Making generic mtl clients/servers

Open
#1,372 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

Having spent some time looking at `hoistClient`, it is not so clear to me how to write a generic lifting function with our current tools. The best I have managed to come up with involves a new type of typeclass and looks kind of inefficient by doing it via natural transformation. On the other hand, it could have next to zero performance cost.

```haskell
class MightHave a t where
hasPrism :: Prism' t a

nt :: ( Has ClientEnv env, MightHave ClientError err
, MonadReader env m, MonadError err m, MonadIO m, Monad m)
=> ClientM a
-> m a
nt cma = do
env <- view hasLens
res <- liftIO $ runClientM cma env
case res of
Left e -> throwError $ review hasPrism e
Right r -> pure r
```

Let's say some lightweight library for prisms was developed in a similar fashion to `data-has`. How much effort would it take to develop a pure mtl `client` producer? Of course, we could also just use `MonadThrow` instead of `MonadError err` if this typeclass idea is too big brain.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.