Skip to content

Commit e7df346

Browse files
committed
Get rid of Protolude dependency
1 parent f06ec65 commit e7df346

File tree

4 files changed

+48
-49
lines changed

4 files changed

+48
-49
lines changed

examples/UserAPI.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
{-# LANGUAGE DataKinds #-}
2-
{-# LANGUAGE DeriveAnyClass #-}
3-
{-# LANGUAGE DeriveGeneric #-}
4-
{-# LANGUAGE MultiParamTypeClasses #-}
5-
{-# LANGUAGE NoImplicitPrelude #-}
6-
{-# LANGUAGE OverloadedStrings #-}
7-
{-# LANGUAGE TypeApplications #-}
8-
{-# LANGUAGE TypeOperators #-}
1+
{-# language DataKinds #-}
2+
{-# language DeriveAnyClass #-}
3+
{-# language DeriveGeneric #-}
4+
{-# language MultiParamTypeClasses #-}
5+
{-# language OverloadedStrings #-}
6+
{-# language TypeApplications #-}
7+
{-# language TypeOperators #-}
98
module UserAPI where
109

11-
import Protolude
12-
1310
import qualified Data.Aeson as Aeson
11+
import Data.Foldable
1412
import qualified Data.HashMap.Lazy as HashMap
13+
import Data.Text (Text)
1514
import qualified Generics.SOP as SOP
15+
import GHC.Generics
1616
import Servant.API
1717

1818
import qualified Language.Elm.Pretty as Pretty

package.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies:
2727
- elm-syntax >= 0.3.0 && < 0.3.1
2828
- haskell-to-elm >= 0.3.0 && < 0.3.1
2929
- http-types >= 0.12.0
30-
- protolude >= 0.2.3
3130
- servant >= 0.16.0
3231
- servant-multipart >= 0.11.0
3332
- text >= 1.2.0

servant-to-elm.cabal

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 06cbc1099ac24f0854793a96e85589086f7cb8409a277a16015d1c10e79f321c
7+
-- hash: 94c98baaa8085cbb210f614d42a13aa56afa0429cec5fe3b3416607ac8cc971c
88

99
name: servant-to-elm
1010
version: 0.4.0.0
@@ -48,7 +48,6 @@ library
4848
, elm-syntax >=0.3.0 && <0.3.1
4949
, haskell-to-elm >=0.3.0 && <0.3.1
5050
, http-types >=0.12.0
51-
, protolude >=0.2.3
5251
, servant >=0.16.0
5352
, servant-multipart >=0.11.0
5453
, text >=1.2.0
@@ -69,7 +68,6 @@ executable user-example
6968
, generics-sop
7069
, haskell-to-elm >=0.3.0 && <0.3.1
7170
, http-types >=0.12.0
72-
, protolude >=0.2.3
7371
, servant
7472
, servant-multipart >=0.11.0
7573
, servant-to-elm
@@ -94,7 +92,6 @@ test-suite servant-to-elm-test
9492
, elm-syntax >=0.3.0 && <0.3.1
9593
, haskell-to-elm >=0.3.0 && <0.3.1
9694
, http-types >=0.12.0
97-
, protolude >=0.2.3
9895
, servant >=0.16.0
9996
, servant-multipart >=0.11.0
10097
, servant-to-elm

src/Servant/To/Elm.hs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
{-# LANGUAGE AllowAmbiguousTypes #-}
2-
{-# LANGUAGE BangPatterns #-}
3-
{-# LANGUAGE DataKinds #-}
4-
{-# LANGUAGE DuplicateRecordFields #-}
5-
{-# LANGUAGE FlexibleContexts #-}
6-
{-# LANGUAGE FlexibleInstances #-}
7-
{-# LANGUAGE GADTs #-}
8-
{-# LANGUAGE MultiParamTypeClasses #-}
9-
{-# LANGUAGE NoImplicitPrelude #-}
10-
{-# LANGUAGE OverloadedStrings #-}
11-
{-# LANGUAGE PolyKinds #-}
12-
{-# LANGUAGE ScopedTypeVariables #-}
13-
{-# LANGUAGE TypeApplications #-}
14-
{-# LANGUAGE TypeOperators #-}
15-
{-# LANGUAGE UndecidableInstances #-}
16-
{-# OPTIONS_GHC -fno-warn-orphans #-}
1+
{-# language AllowAmbiguousTypes #-}
2+
{-# language BangPatterns #-}
3+
{-# language DataKinds #-}
4+
{-# language DuplicateRecordFields #-}
5+
{-# language FlexibleContexts #-}
6+
{-# language FlexibleInstances #-}
7+
{-# language GADTs #-}
8+
{-# language MultiParamTypeClasses #-}
9+
{-# language OverloadedStrings #-}
10+
{-# language PolyKinds #-}
11+
{-# language ScopedTypeVariables #-}
12+
{-# language TypeApplications #-}
13+
{-# language TypeOperators #-}
14+
{-# language UndecidableInstances #-}
15+
{-# options_ghc -fno-warn-orphans #-}
1716
module Servant.To.Elm where
1817

19-
import Protolude hiding (Type, functionName, moduleName)
20-
2118
import qualified Bound
2219
import qualified Data.Aeson as Aeson
2320
import qualified Data.Char as Char
21+
import Data.Proxy
22+
import Data.String
23+
import Data.Text (Text)
2424
import qualified Data.Text as Text
25+
import qualified Data.Text.Encoding as Text
26+
import Data.Void
27+
import GHC.TypeLits
2528
import qualified Network.HTTP.Types as HTTP
2629
import Servant.API ((:<|>), (:>))
2730
import qualified Servant.API as Servant
28-
import qualified Servant.Multipart as Servant
2931
import qualified Servant.API.Modifiers as Servant
32+
import qualified Servant.Multipart as Servant
3033

3134
import Language.Elm.Definition (Definition)
3235
import qualified Language.Elm.Definition as Definition
@@ -49,7 +52,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
4952
(Name.Qualified moduleName functionName)
5053
0
5154
(Bound.toScope $ vacuous $ elmTypeSig)
52-
(panic "expression not closed" <$> lambdaArgs argNames elmLambdaBody)
55+
(error "expression not closed" <$> lambdaArgs argNames elmLambdaBody)
5356
where
5457
functionName =
5558
case _functionName endpoint of
@@ -162,7 +165,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
162165
Expression.App
163166
"Http.request"
164167
(Expression.Record
165-
[ ("method", Expression.String $ toS $ _method endpoint)
168+
[ ("method", Expression.String $ Text.decodeUtf8 $ _method endpoint)
166169
, ("headers", elmHeaders)
167170
, ("url", elmUrl)
168171
, ("body", elmBody)
@@ -325,7 +328,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
325328
, Bound.toScope $
326329
case _returnType endpoint of
327330
Nothing ->
328-
panic "elmRequest: No return type" -- TODO?
331+
error "elmRequest: No return type" -- TODO?
329332

330333
Just (Left Servant.NoContent) ->
331334
Expression.if_ (Expression.apps ("Basics.==") [pure $ Bound.B 1, Expression.String ""])
@@ -367,15 +370,15 @@ elmEndpointDefinition urlBase moduleName endpoint =
367370

368371
headerArgName :: Int -> Text
369372
headerArgName i =
370-
"header" <> show i
373+
"header" <> fromString (show i)
371374

372375
capturedArgName :: Int -> Text
373376
capturedArgName i =
374-
"capture" <> show i
377+
"capture" <> fromString (show i)
375378

376379
paramArgName :: Int -> Text
377380
paramArgName i =
378-
"param" <> show i
381+
"param" <> fromString (show i)
379382

380383
-------------------------------------------------------------------------------
381384
-- * Endpoints
@@ -460,7 +463,7 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
460463
}
461464
where
462465
str =
463-
toS $ symbolVal $ Proxy @symbol
466+
fromString $ symbolVal $ Proxy @symbol
464467

465468
instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
466469
=> HasElmEndpoints (Servant.CaptureAll symbol a :> api) where
@@ -473,15 +476,15 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
473476
}
474477
where
475478
str =
476-
toS $ symbolVal $ Proxy @symbol
479+
fromString $ symbolVal $ Proxy @symbol
477480

478481
instance (Servant.ReflectMethod method, HasElmDecoder Aeson.Value a, list ~ '[Servant.JSON])
479482
=> HasElmEndpoints (Servant.Verb method 200 list a) where
480483
elmEndpoints' prefix =
481484
[ prefix
482485
{ _method = method
483486
, _returnType = Just $ Right $ makeDecoder @Aeson.Value @a
484-
, _functionName = Text.toLower (toS method) : _functionName prefix
487+
, _functionName = Text.toLower (Text.decodeUtf8 method) : _functionName prefix
485488
}
486489
]
487490
where
@@ -493,7 +496,7 @@ instance Servant.ReflectMethod method => HasElmEndpoints (Servant.Verb method 20
493496
[ prefix
494497
{ _method = method
495498
, _returnType = Just $ Left Servant.NoContent
496-
, _functionName = Text.toLower (toS method) : _functionName prefix
499+
, _functionName = Text.toLower (Text.decodeUtf8 method) : _functionName prefix
497500
}
498501
]
499502
where
@@ -509,7 +512,7 @@ instance
509512
elmEndpoints' prefix =
510513
elmEndpoints' @api prefix
511514
{ _headers = _headers prefix <>
512-
[ ( toS $ symbolVal $ Proxy @symbol
515+
[ ( fromString $ symbolVal $ Proxy @symbol
513516
, makeEncoder @(Servant.RequiredArgument mods Text) @(Servant.RequiredArgument mods a)
514517
, case Servant.sbool @(Servant.FoldRequired mods) of
515518
Servant.STrue ->
@@ -532,7 +535,7 @@ instance
532535
{ _url = (_url prefix)
533536
{ _queryString =
534537
_queryString (_url prefix) <>
535-
[ ( toS $ symbolVal $ Proxy @symbol
538+
[ ( fromString $ symbolVal $ Proxy @symbol
536539
, case Servant.sbool @(Servant.FoldRequired mods) of
537540
Servant.STrue ->
538541
Required
@@ -552,7 +555,7 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
552555
{ _url = (_url prefix)
553556
{ _queryString =
554557
_queryString (_url prefix) <>
555-
[ ( toS $ symbolVal $ Proxy @symbol
558+
[ ( fromString $ symbolVal $ Proxy @symbol
556559
, List
557560
, makeEncoder @Text @a
558561
)
@@ -567,7 +570,7 @@ instance (KnownSymbol symbol, HasElmEndpoints api)
567570
{ _url = (_url prefix)
568571
{ _queryString =
569572
_queryString (_url prefix) <>
570-
[ ( toS $ symbolVal $ Proxy @symbol
573+
[ ( fromString $ symbolVal $ Proxy @symbol
571574
, Flag
572575
, Encoder "Basics.identity" "Basics.Bool"
573576
)
@@ -599,7 +602,7 @@ instance (KnownSymbol path, HasElmEndpoints api) => HasElmEndpoints (path :> api
599602
}
600603
where
601604
path =
602-
toS $ symbolVal $ Proxy @path
605+
fromString $ symbolVal $ Proxy @path
603606

604607
instance HasElmEndpoints api => HasElmEndpoints (Servant.RemoteHost :> api) where
605608
elmEndpoints' = elmEndpoints' @api

0 commit comments

Comments
 (0)