@@ -6,7 +6,6 @@
66{-# LANGUAGE FlexibleContexts #-}
77{-# LANGUAGE FlexibleInstances #-}
88{-# LANGUAGE GADTs #-}
9−{-# LANGUAGE KindSignatures #-}
109{-# LANGUAGE LambdaCase #-}
1110{-# LANGUAGE MultiParamTypeClasses #-}
1211{-# LANGUAGE OverloadedStrings #-}
@@ -141,16 +140,19 @@ import Control.Lens
141140 , Wrapped (..)
142141 )
143142import Control.Monad.Except
144−import Control.Monad.Writer (execWriter, tell)
145143import qualified Control.Monad.State.Strict as State
146144import Control.Monad.Trans (lift)
145+import Control.Monad.Writer (execWriter, tell)
146+import Data.Aeson (FromJSON, ToJSON)
147+import qualified Data.Aeson as Aeson
147148import qualified Data.ByteString as BS
148149import qualified Data.ByteString.Lazy as BSL
149−import Data.Dependent.Sum (DSum (..))
150150import Data.Dependent.Map (DMap)
151151import qualified Data.Dependent.Map as DMap
152+import Data.Dependent.Sum (DSum (..))
152153import Data.Either.Validation (Validation (..))
153154import Data.Foldable
155+import Data.Functor (($>))
154156import Data.Functor.Sum
155157import Data.GADT.Compare
156158import Data.GADT.Compare.TH
@@ -163,19 +165,17 @@ import Data.Monoid ((<>))
163165import Data.Set (Set)
164166import qualified Data.Set as Set
165167import Data.Some (Some(Some))
168+import Data.Tabulation
166169import Data.Text (Text)
167−import Data.Text.Lens (IsText, packed, unpacked)
168170import qualified Data.Text as T
169171import qualified Data.Text.Encoding as T
172+import Data.Text.Lens (IsText, packed, unpacked)
170173import Data.Universe
171174import Data.Universe.Some
172175import Network.HTTP.Types.URI
173176import qualified Numeric.Lens
174177import Obelisk.Route.TH
175178import Text.Read (readMaybe)
176−import Data.Tabulation
177−import qualified Data.Aeson as Aeson
178−import Data.Aeson (FromJSON, ToJSON)
179179
180180-- Design goals:
181181-- No start-up time on the frontend (not yet met)
@@ -303,13 +303,13 @@ decode e x = runIdentity (tryDecode e x)
303303-- | Once an 'Encoder' has been checked, so that its check monad has become 'Identity', even if the same is not true of the
304304-- parse monad, we may still attempt to decode with it in its parse monad.
305305tryDecode :: Encoder Identity parse decoded encoded -> encoded -> parse decoded
306−tryDecode (Encoder (Identity impl)) x = _encoderImpl_decode impl x
306+tryDecode (Encoder (Identity impl)) = _encoderImpl_decode impl
307307
308308-- | Similar to 'decode', once an encoder has been checked so that its check monad is Identity, it
309309-- can be used to actually encode by using this. Note that while there's no constraint on the parse monad here,
310310-- one should usually be applying decode and encode to the same 'Encoder'
311311encode :: Encoder Identity parse decoded encoded -> decoded -> encoded
312−encode (Encoder (Identity impl)) x = _encoderImpl_encode impl x
312+encode (Encoder (Identity impl)) = _encoderImpl_encode impl
313313
314314-- | This is a primitive used to build encoders which can't fail to check. It should not be used unless one is
315315-- reasonably certain that the law given for 'EncoderImpl' above holds.
@@ -554,11 +554,11 @@ pathComponentEncoder f = Encoder $ do
554554 unEncoder (pathComponentEncoderImpl (enum1Encoder (extractPathSegment . f)) f')
555555
556556pathComponentEncoderImpl :: forall check parse p. (Monad check, Monad parse)
557− => (Encoder check parse (Some p) (Maybe Text))
557+ => Encoder check parse (Some p) (Maybe Text)
558558 -> (forall a. p a -> Encoder Identity parse a PageName)
559559 -> Encoder check parse (R p) PageName
560−pathComponentEncoderImpl this rest =
561− chainEncoder (lensEncoder (\(_, b) a -> (a, b)) Prelude.fst consEncoder) this rest
560+pathComponentEncoderImpl =
561+ chainEncoder (lensEncoder (\(_, b) a -> (a, b)) Prelude.fst consEncoder)
562562
563563--NOTE: Naming convention in this module is to always talk about things in the *encoding* direction, never in the *decoding* direction
564564
@@ -814,7 +814,7 @@ rPrism
814814 :: forall f f'
815815 . (forall a. Prism' (f a) (f' a))
816816 -> Prism' (R f) (R f')
817−rPrism p = dSumPrism p
817+rPrism = dSumPrism
818818
819819dSumPrism'
820820 :: forall f g a
@@ -826,7 +826,7 @@ dSumGEqPrism
826826 :: GEq f
827827 => f a
828828 -> Prism' (DSum f g) (g a)
829−dSumGEqPrism variant = dSumPrism' $ prism' (\Refl -> variant) (\x -> geq variant x)
829+dSumGEqPrism variant = dSumPrism' $ prism' (\Refl -> variant) (geq variant)
830830
831831-- | Given a 'tag :: f a', make a prism for 'R f'. This generalizes the usual
832832-- prisms for a sum type (the ones that 'mkPrisms' would make), just as 'R'
@@ -993,9 +993,9 @@ obeliskRouteSegment r appRouteSegment = case r of
993993-- be combined with other such segment encoders before 'pathComponentEncoder' turns it into a proper 'Encoder'.
994994resourceRouteSegment :: (MonadError Text check, MonadError Text parse) => ResourceRoute a -> SegmentResult check parse a
995995resourceRouteSegment = \case
996− ResourceRoute_Static -> PathSegment "static" $ pathOnlyEncoderIgnoringQuery
997− ResourceRoute_Ghcjs -> PathSegment "ghcjs" $ pathOnlyEncoder
998− ResourceRoute_JSaddleWarp -> PathSegment "jsaddle" $ jsaddleWarpRouteEncoder
996+ ResourceRoute_Static -> PathSegment "static" pathOnlyEncoderIgnoringQuery
997+ ResourceRoute_Ghcjs -> PathSegment "ghcjs" pathOnlyEncoder
998+ ResourceRoute_JSaddleWarp -> PathSegment "jsaddle" jsaddleWarpRouteEncoder
999999 ResourceRoute_Version -> PathSegment "version" $ unitEncoder mempty
10001000
10011001data JSaddleWarpRoute :: * -> * where
@@ -1007,7 +1007,7 @@ jsaddleWarpRouteEncoder :: (MonadError Text check, MonadError Text parse) => Enc
10071007jsaddleWarpRouteEncoder = pathComponentEncoder $ \case
10081008 JSaddleWarpRoute_JavaScript -> PathSegment "jsaddle.js" $ unitEncoder mempty
10091009 JSaddleWarpRoute_WebSocket -> PathEnd $ unitEncoder mempty
1010− JSaddleWarpRoute_Sync -> PathSegment "sync" $ pathOnlyEncoder
1010+ JSaddleWarpRoute_Sync -> PathSegment "sync" pathOnlyEncoder
10111011
10121012instance GShow appRoute => GShow (ObeliskRoute appRoute) where
10131013 gshowsPrec prec = \case
@@ -1083,7 +1083,7 @@ readShowEncoder :: (MonadError Text parse, Read a, Show a, Applicative check) =>
10831083readShowEncoder = singlePathSegmentEncoder . unsafeTshowEncoder
10841084
10851085integralEncoder :: (MonadError Text parse, Applicative check, Integral a) => Encoder check parse a Integer
1086−integralEncoder = reviewEncoder (Numeric.Lens.integral)
1086+integralEncoder = reviewEncoder Numeric.Lens.integral
10871087
10881088pathSegmentEncoder :: (MonadError Text parse, Applicative check, Cons as as a a) =>
10891089 Encoder check parse (a, (as, b)) (as, b)
@@ -1158,7 +1158,7 @@ pathFieldEncoder fieldEncoder = unsafeEncoder $ do
11581158 fieldEncoderPure f = toEncoder (DMap.findWithDefault (error "bad") f fieldEncoderPureMap)
11591159 pure $ EncoderImpl
11601160 { _encoderImpl_encode = \(x, rest) -> execWriter $ do
1161− _ <- traverseWithField (\f x_i -> tell (pure $ encode (fieldEncoderPure f) x_i) *> pure x_i) x
1161+ _ <- traverseWithField (\f x_i -> tell (pure $ encode (fieldEncoderPure f) x_i) $> x_i) x
11621162 tell rest
11631163 , _encoderImpl_decode = State.runStateT $ tabulateFieldsA $ \f -> State.get >>= \case
11641164 [] -> throwError $ T.pack "not enough path components"