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

Drop using phantom types #33

Open
Open

Description

@cryogenian

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

Activity

  1. cryogenian commented on May 19, 2017

    @cryogenian
    MemberAuthor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions