-
Notifications
You must be signed in to change notification settings - Fork 107
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
Run checkEncoder with template haskell #1087
base: develop
Are you sure you want to change the base?
Conversation
|
||
backend :: Backend BackendRoute FrontendRoute | ||
backend = Backend | ||
{ _backend_run = \serve -> serve $ const $ return () | ||
, _backend_routeEncoder = fullRouteEncoder | ||
, _backend_routeEncoder = hoistCheck (pure . runIdentity) validFullEncoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be _backend_routeEncoder = validFullEncoder
but that's a breaking change, probably best to get adoption first (assuming we merge this)
case fullRouteEncoder of | ||
Left err -> error $ Text.unpack err | ||
Right _ -> | ||
[d| | ||
validFullEncoder :: Encoder Identity Identity (R (FullRoute BackendRoute FrontendRoute)) PageName | ||
Right validFullEncoder = fullRouteEncoder | ||
|] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do this directly in Common.Route
due to stage restriction.
I would also like to have some sort of thisIsTheOnlyBindingYouShouldEdit = fullRouteEncoder
before the case
so that renames to fullRouteEncoder
in "userland" only require a single rename in this weird place (and thus unlikely to get out of sync) but that requires yet another module due to stage restriction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't able to pull this into a DRY util as there's no way to get a Lift
instance for Encoder
to splice back in.
At most we could have a util taking in Encoder check parse a b
for the check and Name
/Dec
for use in the new binding and pass both "forms" of fullRouteEncoder
. Maybe it'd be worth putting that in Obelisk.Route
?
Got the idea of using TH for encoders long ago from @ryantrinkle.
This has the side effect of speeding up reloads by doing the check only whenCommon.Route
is modified instead of every reload. Likely not to be noticed unless relying on largeUniverse
instances.EDIT: Hmm no it doesn't. It's pretty unsatisfying that the lack of a
Lift
instance (at least when using->
andKleisli m
categories) means we need to check twice. All we get is upgrading fails-at-startup to fails-at-compile-time.I marked this as draft because everytime
Common.Route.Checked
is recompiled in ghci (and thusob
commands) I start gettinguntil I recompile
Backend.hs
again. Not usingvalidFullEncoder
inBackend.hs
also stops it from triggeringI have:
develop
branchhlint .
(lint found code you did not write can be left alone)$(nix-build -A selftest --no-out-link)
nix-build release.nix -A build.x86_64-linux --no-out-link
(orx86_64-darwin
on macOS)