From 494b90bf18f3ee73a8ccd3ecf50b1e31034e061a Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 21 May 2021 14:17:00 -0400 Subject: [PATCH] ... fundeps no longer needed Because ejecting staticRoutes also ejected the 'model' class argument --- src/Ema/App.hs | 6 +++--- src/Ema/Class.hs | 5 ++--- src/Ema/Example/Ex02_Basic.hs | 2 +- src/Ema/Example/Ex03_Clock.hs | 2 +- src/Ema/Generate.hs | 4 ++-- src/Ema/Route.hs | 8 ++++---- src/Ema/Server.hs | 4 ++-- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Ema/App.hs b/src/Ema/App.hs index 3aa58f9..0901311 100644 --- a/src/Ema/App.hs +++ b/src/Ema/App.hs @@ -48,7 +48,7 @@ runEmaPure render = do -- exits, and vice-versa. runEma :: forall model route. - (Ema model route, Show route) => + (Ema route, Show route) => (model -> [route]) -> -- | How to render a route, given the model (CLI.Action -> model -> route -> LByteString) -> @@ -65,7 +65,7 @@ runEma staticRoutes render runModel = do -- Useful if you are handling CLI arguments yourself. runEmaWithCli :: forall model route. - (Ema model route, Show route) => + (Ema route, Show route) => Cli -> (model -> [route]) -> -- | How to render a route, given the model @@ -91,7 +91,7 @@ runEmaWithCli cli staticRoutes render runModel = do -- | Run Ema live dev server runEmaWithCliInCwd :: forall model route m. - (MonadEma m, Ema model route, Show route) => + (MonadEma m, Ema route, Show route) => -- | CLI arguments CLI.Action -> -- | Your site model type, as a @LVar@ in order to support modifications over diff --git a/src/Ema/Class.hs b/src/Ema/Class.hs index 105b215..74c436f 100644 --- a/src/Ema/Class.hs +++ b/src/Ema/Class.hs @@ -1,6 +1,5 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DefaultSignatures #-} -{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} @@ -17,7 +16,7 @@ type MonadEma m = ) -- | Enrich a model to work with Ema -class Ema model route | route -> model where +class Ema route where -- How to convert URLs to/from routes encodeRoute :: route -> [Slug] decodeRoute :: [Slug] -> Maybe route @@ -29,7 +28,7 @@ class Ema model route | route -> model where staticAssets Proxy = mempty -- | The unit model is useful when using Ema in pure fashion (see @Ema.runEmaPure@) with a single route (index.html) only. -instance Ema () () where +instance Ema () where encodeRoute () = [] decodeRoute = \case [] -> Just () diff --git a/src/Ema/Example/Ex02_Basic.hs b/src/Ema/Example/Ex02_Basic.hs index 3e78b24..df96bf5 100644 --- a/src/Ema/Example/Ex02_Basic.hs +++ b/src/Ema/Example/Ex02_Basic.hs @@ -25,7 +25,7 @@ data Route data Model = Model Text -instance Ema Model Route where +instance Ema Route where encodeRoute = \case Index -> mempty About -> one "about" diff --git a/src/Ema/Example/Ex03_Clock.hs b/src/Ema/Example/Ex03_Clock.hs index f5ca422..b63d416 100644 --- a/src/Ema/Example/Ex03_Clock.hs +++ b/src/Ema/Example/Ex03_Clock.hs @@ -25,7 +25,7 @@ data Route | OnlyTime deriving (Show, Enum, Bounded) -instance Ema UTCTime Route where +instance Ema Route where encodeRoute = \case Index -> mempty OnlyTime -> one "time" diff --git a/src/Ema/Generate.hs b/src/Ema/Generate.hs index 2ea9fb0..96a0883 100644 --- a/src/Ema/Generate.hs +++ b/src/Ema/Generate.hs @@ -17,7 +17,7 @@ log = logWithoutLoc "Generate" generate :: forall model route m. - (MonadEma m, Ema model route) => + (MonadEma m, Ema route) => FilePath -> model -> [route] -> @@ -28,7 +28,7 @@ generate dest model routes render = do error $ "Destination does not exist: " <> toText dest log LevelInfo $ "Writing " <> show (length routes) <> " routes" forM_ routes $ \r -> do - let fp = dest routeFile @model r + let fp = dest routeFile r log LevelInfo $ toText $ "W " <> fp let !s = render model r liftIO $ do diff --git a/src/Ema/Route.hs b/src/Ema/Route.hs index 268aab3..24af4da 100644 --- a/src/Ema/Route.hs +++ b/src/Ema/Route.hs @@ -24,10 +24,10 @@ import Ema.Route.UrlStrategy -- -- As the returned URL is relative, you will have to either make it absolute (by -- prepending with `/`) or set the `` URL in your HTML head element. -routeUrl :: forall a r. Ema a r => r -> Text +routeUrl :: forall r. Ema r => r -> Text routeUrl r = - slugRelUrlWithStrategy def (encodeRoute @a r) + slugRelUrlWithStrategy def (encodeRoute r) -routeFile :: forall a r. Ema a r => r -> FilePath +routeFile :: forall r. Ema r => r -> FilePath routeFile r = - slugFileWithStrategy def (encodeRoute @a r) + slugFileWithStrategy def (encodeRoute r) diff --git a/src/Ema/Server.hs b/src/Ema/Server.hs index 52c62b9..8496769 100644 --- a/src/Ema/Server.hs +++ b/src/Ema/Server.hs @@ -25,7 +25,7 @@ import Text.Printf (printf) runServerWithWebSocketHotReload :: forall model route m. - (Ema model route, Show route, MonadEma m) => + (Ema route, Show route, MonadEma m) => Int -> LVar model -> (model -> route -> LByteString) -> @@ -127,7 +127,7 @@ runServerWithWebSocketHotReload port model render = do <> show @Text err <> "

Once you fix your code this page will automatically update." routeFromPathInfo = - decodeRoute @model . fmap Slug.decodeSlug + decodeRoute @route . fmap Slug.decodeSlug -- TODO: It would be good have this also get us the stack trace. unsafeCatch :: Exception e => a -> (e -> a) -> a unsafeCatch x f = unsafePerformIO $ catch (seq x $ pure x) (pure . f)