Run checkEncoder with template haskell#1087
Run checkEncoder with template haskell#1087alexfmpe wants to merge 2 commits intoobsidiansystems:developfrom
Conversation
| backend = Backend | ||
| { _backend_run = \serve -> serve $ const $ return () | ||
| , _backend_routeEncoder = fullRouteEncoder | ||
| , _backend_routeEncoder = hoistCheck (pure . runIdentity) validFullEncoder |
There was a problem hiding this comment.
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.
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.
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.Routeis modified instead of every reload. Likely not to be noticed unless relying on largeUniverseinstances.EDIT: Hmm no it doesn't. It's pretty unsatisfying that the lack of a
Liftinstance (at least when using->andKleisli mcategories) 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.Checkedis recompiled in ghci (and thusobcommands) I start gettinguntil I recompile
Backend.hsagain. Not usingvalidFullEncoderinBackend.hsalso stops it from triggeringI have:
developbranchhlint .(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-darwinon macOS)