git.iko.soy/rowtype-yoga/purescript-yoga-fetch-om
on main help sign in
Add polymorphic helper to enable forall at record level

- Add 'polymorphic' function to cast clients to polymorphic signatures - Users can now write: api :: forall ctx err. { ... } - Example updated to show polymorphic type signature usage

commit9df43d141cb85650630c4d12cdb354146a572928 authorMark <mark.eibes@gmail.com> dateMon 9 Feb 2026, 14:47 (8 months ago) parent0703bd7
2 files changed+23−8
src/Yoga/Fetch/Om.purs+13 test/Complete.Example.purs+10−8
src/Yoga/Fetch/Om.purs+13
@@ -1,6 +1,7 @@
11module Yoga.Fetch.Om
22 ( client
33 , deriveClient
4+ , polymorphic
45 , class DeriveClient
56 , deriveClientImpl
67 , class DeriveClientRL
@@ -120,6 +121,18 @@ client baseUrl = deriveClientImpl baseUrl (Proxy :: _ { | routesRow })
120121deriveClient :: forall @routesRow clientsRow. DeriveClient routesRow clientsRow => String -> Record clientsRow
121122deriveClient baseUrl = deriveClientImpl baseUrl (Proxy :: _ { | routesRow })
122123
124+-- | Cast a generated client to a polymorphic type signature
125+-- | This allows you to add explicit forall quantification for better documentation
126+-- |
127+-- | ```purescript
128+-- | api :: forall ctx err.
129+-- | { getUser :: { id :: Int } -> Om ctx (notFound :: ErrorMessage | err) User
130+-- | }
131+-- | api = polymorphic $ client @UserAPI "https://api.example.com"
132+-- | ```
133+polymorphic :: forall a b. a -> b
134+polymorphic = unsafeCoerce
135+
123136instance
124137 ( RowToList routesRow rl
125138 , DeriveClientRL rl () clientsRow
test/Complete.Example.purs+10−8
@@ -5,7 +5,7 @@ import Prelude
55import Data.Array (length)
66import Data.Maybe (Maybe(..))
77import Effect.Class.Console (log)
8−import Yoga.Fetch.Om (GET, POST, PUT, DELETE, Route, JSON, Path, type (/), type (:), type (:?), client)
8+import Yoga.Fetch.Om (GET, POST, PUT, DELETE, Route, JSON, Path, type (/), type (:), type (:?), client, polymorphic)
99import Yoga.Om (Om, handleErrors)
1010
1111type User =
@@ -73,15 +73,17 @@ type UserAPI =
7373 )
7474 }
7575
76+-- Generated client with polymorphic type annotation
7677api
77− :: { createUser :: CreateUserRequest -> Om {} (badRequest :: ErrorMessage) User
78− , createUserAuth :: { authorization :: String } -> CreateUserRequest -> Om {} (badRequest :: ErrorMessage) User
79− , deleteUser :: { id :: Int } -> Om {} (notFound :: ErrorMessage) {}
80− , getUser :: { id :: Int } -> Om {} (notFound :: ErrorMessage) User
81− , listUsers :: { limit :: Maybe Int, offset :: Maybe Int } -> Om {} () (Array User)
82− , updateUser :: { id :: Int } -> UpdateUserRequest -> Om {} (badRequest :: ErrorMessage, notFound :: ErrorMessage) User
78+ :: forall ctx err
79+ . { createUser :: CreateUserRequest -> Om ctx (badRequest :: ErrorMessage | err) User
80+ , createUserAuth :: { authorization :: String } -> CreateUserRequest -> Om ctx (badRequest :: ErrorMessage | err) User
81+ , deleteUser :: { id :: Int } -> Om ctx (notFound :: ErrorMessage | err) {}
82+ , getUser :: { id :: Int } -> Om ctx (notFound :: ErrorMessage | err) User
83+ , listUsers :: { limit :: Maybe Int, offset :: Maybe Int } -> Om ctx err (Array User)
84+ , updateUser :: { id :: Int } -> UpdateUserRequest -> Om ctx (badRequest :: ErrorMessage, notFound :: ErrorMessage | err) User
8385 }
84−api = client @UserAPI "https://api.example.com"
86+api = polymorphic $ client @UserAPI "https://api.example.com"
8587
8688exampleGetUser :: Om {} (notFound :: ErrorMessage) Unit
8789exampleGetUser = do