Skip to content

Use type level checking for PureScript #20

@gaku-sei

Description

@gaku-sei

The current PureScript generator will generate some cumbresome code:

make = ... -- Meant to both type check and generate, at runtime, the class

m1 :: Tailwind
m1 = "m-1"

m2 :: Tailwind
m2 = "m-2"

-- And so on...

This comes with 2 downsides:

  1. It's extremely verbose, taking 4 lines per css class, when tailwind generates 25,000 classes, do the math 😄
  2. As mentioned in the code snippet above, there is a compile validatation, but also some runtime computation, since we need to turn a list of classes into a string

The idea is to use type level checking (close to what https://github.com/kcsongor/purescript-safe-printf achieves):

-- Type level logic

type M1 = SProxy "m-1"

type M2 = SProxy "m-2"

And it could be used as follow:

myClasses = Tailwind.validate (SProxy :: _ "m-1 m-2")

This approach comes with 3 benefits:

  1. It's shorter
  2. No runtime cost, validate will just take the compile time string, and reflect it into the runtime realm
  3. Can potentially handles some exotic class names

It also comes with 2 drawbacks:

  1. Less flexible (bye bye Monoid and Foldable goodies)
  2. It's more verbose on the call side (because of the SProxy value, unfortunately PureScript used to have the following syntax: @"m-1 m-2" like in Haskell but it got dropped).

I think the change should be opt-in, and we should expose 2 generators: purescript and purescript-typelevel

Metadata

Metadata

Assignees

No one assigned

    Labels

    command:generateRelated to the `pyaco generate` commandenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions