haskell-servant / haskell-servant/servant
servant-foreign and preambles
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
In many cases, it may be the case that a certain combinator requires some import or code *outside* of the client-function definition. An example is [JS for servant-auth](https://github.com/plow-technologies/servant-auth/issues/31). It would be great if there were support for this.
These will admittedly be language-dependent.
The simplest way I can think of for this is to have a separate class for this metadata:
```haskell
data Preamble = Preamble
{ first :: [T.Text]
, second :: [T.Text]
}
instance Monoid Preamble
class HasForeignPreamble lang api where
foreignPreamble :: Proxy lang -> Proxy api -> Preamble
instance HasForeignPreamble lang (a :<|> b) where
foreignPreamble _ _ = foreignPreamble proxyA <> foreignPreamble proxyB
instance HasForeignPreamble lang (a :> b) where
foreignPreamble _ _ = foreignPreamble proxyB
-- or without overlapping instance, and with a default impl (though that would be backward-incompatible)
```
But I don't know the `servant-foreign` codebase all that well!
Contributor guide
Assessment
This issue has not been assessed yet.