Mateusz Kowalczyk | 11 Aug 11:43 2014
Picon

Updating code to work with vinyl 0.4

Hi,

I'm looking for some help in helping to migrate to vinyl-0.4 from
earlier version. I'll first outline how I currently have things set up
and then ask a few questions. For reference the whole project is at [1].
You can just skip to questions in the end if you want to.

I have a small project which goes out to a few sites, fetches some
similar XML data, parses some fields and returns a data type. My
original attempt was to generate a data type per site but that was very
ugly: couldn't reuse functions, accessors, anything. So I then turned to
vinyl and have the following solution:

I have a bunch of common fields defined like this:

--
file_url ∷ "file_url" ::: String
file_url = Field

parent_id ∷ "parent_id" ::: Maybe Integer
parent_id = Field
--
and so on.

I'm using HXT to process the XML I get from each site so I have created
many HXT arrows creating each field like this:

--
parent_idA ∷ (Functor (cat XmlTree), ArrowXml cat) ⇒
             cat XmlTree (PlainRec '["parent_id" ::: Maybe Integer])
(Continue reading)

adam vogt | 11 Aug 17:04 2014
Picon

Re: Updating code to work with vinyl 0.4

Hi Mateusz,

You can write  'Foo :~> [t| Maybe String |] to make the generated code include a

  type instance App ElF Foo = Maybe String

Unfortunately the type of (:~>) includes some un-exported classes, so
you have to dig into vinyl's source to see which arguments are
actually allowed.

I'm not sure exactly what you mean by

> PlainRec ElF (ParentId ': '[])” works but is ugly

But maybe it's worth just using the Data.Vinyl.Universe.Field (ex.
http://lpaste.net/109203), if you would rather write

  PlainRec ElField '["parent_id" ::: Maybe Integer])

than,

  PlainRec ElF '[ParentId]

Or maybe you want to use Symbol together with your own universe:

  makeUniverse' ''Symbol "ElF"
  semantics ''ElF [ [t| "height" |] :~> [t| Maybe Int |] ]
  -- type instance App ElF "height" = Maybe Int -- or just write those by-hand

  height = Proxy :: Proxy "height" -- there seems to be no code
(Continue reading)

Mateusz Kowalczyk | 12 Aug 09:27 2014
Picon

Re: Updating code to work with vinyl 0.4

On 08/11/2014 05:04 PM, adam vogt wrote:
> Hi Mateusz,
> 
> You can write  'Foo :~> [t| Maybe String |] to make the generated code include a
> 
>   type instance App ElF Foo = Maybe String
> 
> Unfortunately the type of (:~>) includes some un-exported classes, so
> you have to dig into vinyl's source to see which arguments are
> actually allowed.
> 
> 
> I'm not sure exactly what you mean by
> 
>> PlainRec ElF (ParentId ': '[])” works but is ugly
> 
> But maybe it's worth just using the Data.Vinyl.Universe.Field (ex.
> http://lpaste.net/109203), if you would rather write
> 
>   PlainRec ElField '["parent_id" ::: Maybe Integer])
> 
> than,
> 
>   PlainRec ElF '[ParentId]
> 
> Or maybe you want to use Symbol together with your own universe:
> 
>   makeUniverse' ''Symbol "ElF"
>   semantics ''ElF [ [t| "height" |] :~> [t| Maybe Int |] ]
>   -- type instance App ElF "height" = Maybe Int -- or just write those by-hand
(Continue reading)


Gmane