[grapefruit] Sampling the record of signals

Roman Cheplyaka roma at ro-che.info
Fri Apr 24 03:33:49 EDT 2009


Great explanation, thanks!

* Wolfgang Jeltsch <g9ks157k at acme.softbase.org> [2009-04-23 18:18:33+0200]
> Am Mittwoch, 22. April 2009 17:59 schrieb Roman Cheplyaka:
> > Can someone show me how to use map on records?
> > Precisely, I have a record of CSignals and want to sample them (with the
> > same sampler) and to get record of SSignals.
> 
> Hello Roman,
> 
> Data.Record.map uses the same record type for the source and destination 
> record. The only thing that can differ is the style.
> 
> If you use signal style records, your source record type will look like this:
> 
>     X :& CSignal `Of` val_1 :& … :& CSignal `Of` val_n
> 
> However, your destination record type will look like this:
> 
>     X :& SSignal `Of` val_1 :& … :& SSignal `Of` val_n
> 
> So both differ.
> 
> The solution would be to remove the concrete signal type (CSignal or SSignal) 
> from the record type and put it into the style instead. This is the same as 
> what’s already done with signal, producer and consumer records. Their record 
> types only contain sort types of the form signal `Of` val. It’s the concrete 
> style that transforms this into signal era val, Consumer signal val or 
> Producer signal val.
> 
> So what you should do is using record types like this:
> 
>     X :& val_1 :& … :& val_n
> 
> Then define a new “homegenous signal style” like this:
> 
>     data HomSignalStyle (signal :: * -> * -> *) era
> 
>     instance Style (HomSignalStyle signal era) where
> 
>         type K (HomSignalStyle signal era) = PlainKind
> 
>     type instance Value (HomSignalStyle signal era) val = signal era val
> 
> Homegenous signal records are now defined to be signal records where not only 
> the era but also the signal type (CSignal, SSignal, …) is the same for all 
> record fields.
> 
> Now you can implement the sampling of all record fields:
> 
>     samplingTransformerPiece
>         :: DSignal era ()
>         -> TransformerPiece
>                 (HomSignalStyle CSignal era)
>                 (HomSignalStyle SSignal era)
>     samplingTransformerPiece sampler = TransformerPiece $ (sampler #>)
> 
>     sampleRecord :: (Record PlainKind record) =>
>             record (HomSignalStyle CSignal era) ->
>             record (HomSignalStyle SSignal era)
>     sampleRecord = Data.Record.map samplingTransformerPiece
> 
> Warning! All code in this e-mail is untested. :-( 
> 
> Please ask if this is not yet clear (which would be understandable :-) ).
> 
> Best wishes,
> Wolfgang
> 
> _______________________________________________
> Grapefruit mailing list
> Grapefruit at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/grapefruit

-- 
Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain



More information about the Grapefruit mailing list