@@ -122,6 +122,34 @@ type family Elem (a :: *) (ls::[*]) :: Constraint where
122 Elem a (a ': list) = ()
122 Elem a (a ': list) = ()
123 Elem a (b ': list) = Elem a list
123 Elem a (b ': list) = Elem a list
125+-- | 'HasForeignType' maps Haskell types with types in the target
126+-- language of your backend. For example, let's say you're
127+-- implementing a backend to some language __X__:
129+-- > -- First you need to create a dummy type to parametrize your
133+-- > -- If the language __X__ is dynamically typed then you only need
134+-- > -- a catch all instance of a form
135+-- > instance HasForeignType LangX a where
136+-- > typeFor _ _ = empty
138+-- > -- Otherwise you define instances for the types you need
139+-- > instance HasForeignType LangX Int where
140+-- > typeFor _ _ = "intX"
142+-- > -- Or for example in case of lists
143+-- > instance HasForeignType LangX a => HasForeignType LangX [a] where
144+-- > typeFor lang _ = "listX of " <> typeFor lang (Proxy :: Proxy a)
146+-- Finally to generate list of information about all the endpoints for
147+-- an API you create a function of a form:
149+-- > getEndpoints :: (HasForeign LangX api, GenerateList (Foreign api))
150+-- > => Proxy api -> [Req]
151+-- > getEndpoints api = listFromAPI (Proxy :: Proxy LangX) api
125class HasForeignType lang a where
153class HasForeignType lang a where
126 typeFor :: Proxy lang -> Proxy a -> ForeignType
154 typeFor :: Proxy lang -> Proxy a -> ForeignType