slamdata / purescript-echarts

Purescript bindings for Baidu's Echarts library
36 stars 16 forks source link

Drop using phantom types #33

Open cryogenian opened 7 years ago

cryogenian commented 7 years ago

Now with PS supporting polymorphic labels there is no need in phantom rows. We can use RowCons for this. E.g.

lineSeries :: forall r rr. RowCons "series" LineSeries r rr => LineSeriesR -> r -> rr
lineSeries = ...

This also removes need of returning Foreign from getOption because we can know that field is set and can use https://github.com/purescript/purescript/blob/e4ff177017f1411ad4cbeade129cfe1bb52d6e99/examples/passing/PolyLabels.purs#L21

cryogenian commented 7 years ago

Using Union for this is kinda problematic because we need

newtype Series = Series (Exists Identity) mkLineSeries :: forall r1 r2. Union r1 r2 LineSeriesRow => Record r1 -> Series mkLineSeries = unsafeCoerce

mkBarSeries :: forall r1 r2. Union r1 r2 BarSeriesRow => Record r1 -> Series mkBarSeries = unsafeCoerce

runLineSeries :: forall res. Series -> (forall r1 r2. Union r1 r2 LineSeriesRow => Maybe (Record r1) -> res) -> res runLineSeries = ...

foldSeries :: forall res . Series -> -> (forall r1 r2. Union r1 r2 LineSeries => Record r1 -> res) -> (forall r1 r2. Union r1 r2 BarSeries => Record r1 -> res) -> ... -> res


The second one works but API isn't soo fancy 
```purescript
mkChart 
  { animationDuration: \i -> i * 100
  , textStyle: mkTextStyle { fontSize: 14 }
  , series: [ mkLineSeries lineSeries, mkBarSeries barSeries ]  
  }