[Haskell-cafe] api-tools questions

Karsten Gebbert k at ioctl.it
Wed Sep 10 20:05:54 UTC 2014


Chris,

thank you for the pointer, that is really helpful indeed!

I see that you are using Haskell types for some fields, rather than
types defined in your API. When I, for instance, try to use Map as field
type, with String as both key and value type, I get an error:

   myrec :: MyRec
     // a map
     = record 
       myfield ::  Map String String

   Exception when trying to run compile-time code:
      Syntax error at line 345, column 20 (@8596): [(AlexPn 8596 345 20,TypeIden "String"),(AlexPn 8603 345 27,TypeIden "String")]

I suspect this is only the case with types that are parameterized over
others, as a type synonym seems to make this possible anyways. Is there
a better way to deal with this than the one I mentioned?

Thanks for your help,

karsten

Chris Dornan <chris at chrisdornan.com> writes:

> 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/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 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