[Haskell-cafe] api-tools questions

Chris Dornan chris at chrisdornan.com
Thu Sep 25 12:10:22 UTC 2014


You might also find the keystore[0] package useful as it makes use of this
technique
in several places. See, for example the definition of Pattern in the
`Data.Keystore.Types.Schema`[1] and `Data.Keystore.Types`[2].

(Btw, the keystone docs are not building on Hackage for the latest
version; they build
on our private Hackage server and they did for earlier versions of
Hackage[3];
I will try to fix them tonight.)

Chris

[0] http://hackage.haskell.org/package/keystore
[1] 
https://github.com/cdornan/keystore/blob/master/src/Data/KeyStore/Types/Sch
ema.hs#L179
[2] 
https://github.com/cdornan/keystore/blob/master/src/Data/KeyStore/Types.hs#
L68

[3] http://hackage.haskell.org/package/keystore-0.5.0.4

On 09/09/2014 16:16, "Adam Gundry" <adam at well-typed.com> wrote:

>Hi Karsten,
>
>This isn't very well documented, but there is a (hidden) feature of
>api-tools that should do what you want. If you say something like
>
>    mt :: MyTime = basic string with inj_MyTime, prj_MyTime
>
>then you can define your own type MyTime and give conversion functions
>inj_MyTime and prj_MyTime to convert back and forth from a
>newtype-wrapped Text. (In fact, you could probably use UTCTime as
>MyTime...). More precisely, api-tools will generate something like
>
>    newtype REP__MyTime = REP__MyTime Text
>
>and you will need to implement
>
>    inj_MyTime :: REP__MyTime -> ParserWithErrs MyTime
>    prj_MyTime :: MyTime -> REP__MyTime
>
>I hope this helps, and further questions or documentation contributions
>are very welcome!
>
>Cheers,
>
>Adam
>
>
>On 09/09/14 14:02, Karsten Gebbert wrote:
>> Hi All,
>> 
>> I have a question concerning the api-tools package.
>> 
>> Its not clear from the tests, sources or the tutorial how I can use
>> other date/time formats that the default `utc` type can handle. I'm
>> trying to wrap a JSON API that is not under my control, so I have to
>> adhere to whatever I get back from it. Could anybody with experience
>> with the package point me to some example, relevant bits in the sources
>> or a tip how to do it?
>> 
>> I'm planning to create some more documentation around the package to
>> contribute back once I figured out a few more details, because I think
>> its quite a useful abstraction when dealing with (foreign) APIs IMO.
>> 
>> Thanks already for any hints,
>> 
>> karsten
>
>
>-- 
>Adam Gundry, Haskell Consultant
>Well-Typed LLP, http://www.well-typed.com/
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe




More information about the Haskell-Cafe mailing list