Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use type level checking for PureScript #20

Open
gaku-sei opened this issue Sep 9, 2020 · 0 comments
Open

Use type level checking for PureScript #20

gaku-sei opened this issue Sep 9, 2020 · 0 comments
Labels
command:generate Related to the `pyaco generate` command enhancement New feature or request

Comments

@gaku-sei
Copy link
Contributor

gaku-sei commented Sep 9, 2020

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

@gaku-sei gaku-sei added command:generate Related to the `pyaco generate` command enhancement New feature or request labels Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command:generate Related to the `pyaco generate` command enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant