[Haskell-cafe] api-tools questions

Chris Dornan chris at chrisdornan.com
Thu Sep 25 12:10:23 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].

Chris

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


On 09/09/2014 17:20, "Karsten Gebbert" <k at ioctl.it> wrote:

>Excellent, thanks a lot Adam. I'll open a PR when I'm through with this
>project :)
>
>Adam Gundry <adam at well-typed.com> writes:
>
>> 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