Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Drop using phantom types #33

Open
cryogenian opened this issue Apr 3, 2017 · 1 comment
Open

Drop using phantom types #33

cryogenian opened this issue Apr 3, 2017 · 1 comment

Comments

@cryogenian
Copy link
Member

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
Copy link
Member Author

Using Union for this is kinda problematic because we need

  • Be able to have row with fields that are subset of corresponding field in Option and may be missing
  • series can have different configuration --> universal type parameters with Union constraints won't work too --> only existential things like
newtype TextStyle = TextStyle (Exists Identity) 
mkTextStyle :: forall r1 r2. Union r1 r2 TextStyleRow => Record r1 -> TextStyle 
mkTextStyle = unsafeCoerce 
runTextStyle :: forall res. TextStyle -> (forall r1 r2. Union r1 r2 TextStyleRow => Record r1 -> res) -> res
runTextStyle = unsafeCoerce runExists

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

mkChart 
  { animationDuration: \i -> i * 100
  , textStyle: mkTextStyle { fontSize: 14 }
  , series: [ mkLineSeries lineSeries, mkBarSeries barSeries ]  
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant