profile
viewpoint

batebobo/fp1718 1

Notes and exercises for the Functional Programming course taught at @FMI

ChaosGroup/servant-elm-street 0

Generate elm requests, with types, and JSON encoders, and decoders derived by elm-street, given a servant API.

DenisBelinov/FunctionalProgramming 0

Tasks and exercises for a class on Functional Programming

dtaskoff/skip-var 0

Implementation of skip variables (a special case of skip channels)

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

 elmPrimToDoc = \case  mkTypeSignature :: Req ElmDefinition -> Doc mkTypeSignature request =-  (hsep . punctuate " ->") ("String" : catMaybes [toMsgType, returnType])+  (hsep . punctuate "->") ("String" : catMaybes [toMsgType, returnType])

Did you verify that this doesn't cause an issue?

MaggieVL

comment created time in an hour

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

 name:                servant-elm-street version:             0.1.0.0-github:              "githubuser/servant-elm-street"+github:              "ChaosGroup//servant-elm-street" license:             BSD3-author:              "Author name here"-maintainer:          "example@example.com"-copyright:           "2021 Author name here"+author:              "Magdalena Lungolova"+maintainer:          "mvlungolova@gmail.com"+copyright:           "Copyright 2021 Chaos Software OOD"  extra-source-files: - README.md-- ChangeLog.md -# Metadata used when publishing your package-# synopsis:            Short description of your package-# category:            Web--# To avoid duplicated efforts in documentation and dealing with the-# complications of embedding Haddock markup inside cabal files, it is-# common to point users to the README.md file.-description:         Please see the README on GitHub at <https://github.com/githubuser/servant-elm-street#readme>--dependencies:-- base >= 4.7 && < 5+description:         Please see the README on GitHub at <https://github.com/ChaosGroup/servant-elm-street/blob/main/README.md>  library:   source-dirs: src  dependencies: - servant-foreign - text-- servant-elm - base >= 4.7 && < 5 - aeson-- casing - elm-street-- filepath - servant-- servant-server - wai-- warp-- servant-js - random

What do you need random f or?

MaggieVL

comment created time in an hour

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+name:                servant-elm-street+version:             0.1.0.0+github:              "githubuser/servant-elm-street"+license:             BSD3+author:              "Author name here"+maintainer:          "example@example.com"+copyright:           "2021 Author name here"

@dtaskoff please verify this when you're here

MaggieVL

comment created time in an hour

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}

As we discussed, it should instead be moved to an examples folder in a project of its own.

MaggieVL

comment created time in an hour

PullRequestReviewEvent

pull request commentphadej/staged-gg

Add Generic generics

As someone who is not too much into GHC.Generic and especially not that informed about staged generics, can I ask (if you have the time to answer) - what does this bring? Easier usage of staged-gg, since now whenever you have deriving stock Generic you can get staged-ggs Generic? And does it still guarantee that the intermediate representation will still all be eliminated? (or am I entirely misunderstanding what this pr does?)

treeowl

comment created time in 3 hours

issue openedhaskell/haskell-language-server

Export action on type family exports with constructors (Tyfam(..))

Your environment

HLS version: 1.5.1 Which OS do you use: Debian Which LSP client (editor/plugin) do you use: LanguageClient-neovim

resolver: nightly-2021-09-12

Steps to reproduce

Add a file with a type family, with an empty export list. Use the "export definition" action on the type family. HLS generates an export with exported constructors, even though type families don't have constructors.

Expected behaviour

An export without constructors.

Actual behaviour

An export with constructors, which don't exist, causing an additional warning.

created time in 18 hours

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

 cabal.project.local cabal.project.local~ .HTF/ .ghc.environment.*+*~+src/copy/

So you should remove this from the .gitignore

MaggieVL

comment created time in a day

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+name:                servant-elm-street+version:             0.1.0.0+github:              "githubuser/servant-elm-street"+license:             BSD3+author:              "Author name here"+maintainer:          "example@example.com"+copyright:           "2021 Author name here"++extra-source-files:+- README.md+- ChangeLog.md++# Metadata used when publishing your package+# synopsis:            Short description of your package+# category:            Web++# To avoid duplicated efforts in documentation and dealing with the+# complications of embedding Haddock markup inside cabal files, it is+# common to point users to the README.md file.+description:         Please see the README on GitHub at <https://github.com/githubuser/servant-elm-street#readme>++dependencies:+- base >= 4.7 && < 5++library:+  source-dirs: src++dependencies:+- servant-foreign+- text+- servant-elm+- base >= 4.7 && < 5+- aeson+- casing+- elm-street+- filepath+- servant+- servant-server+- wai+- warp+- servant-js+- random+- elm-bridge+- wl-pprint-text+- microlens+

(of course you should also recompile afterwards to fix all the warnings)

MaggieVL

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+name:                servant-elm-street+version:             0.1.0.0+github:              "githubuser/servant-elm-street"+license:             BSD3+author:              "Author name here"+maintainer:          "example@example.com"+copyright:           "2021 Author name here"++extra-source-files:+- README.md+- ChangeLog.md++# Metadata used when publishing your package+# synopsis:            Short description of your package+# category:            Web++# To avoid duplicated efforts in documentation and dealing with the+# complications of embedding Haddock markup inside cabal files, it is+# common to point users to the README.md file.+description:         Please see the README on GitHub at <https://github.com/githubuser/servant-elm-street#readme>++dependencies:+- base >= 4.7 && < 5++library:+  source-dirs: src++dependencies:+- servant-foreign+- text+- servant-elm+- base >= 4.7 && < 5+- aeson+- casing+- elm-street+- filepath+- servant+- servant-server+- wai+- warp+- servant-js+- random+- elm-bridge+- wl-pprint-text+- microlens+

We should turn on more warnings and error out on warnings. Here's a snippet to put in this file:

ghc-options:
- -Wall
- -Werror
- -Wincomplete-uni-patterns
- -Wredundant-constraints
- -Widentities
- -Wincomplete-record-updates
- -Wmissing-deriving-strategies
- -Wmissing-export-lists
MaggieVL

comment created time in 4 days

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}

Try removing it.

MaggieVL

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}

Highly doubtful we need this.

MaggieVL

comment created time in 4 days

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}++module ServantElm+  ( elmForAPI,+  )+where++import Data.Aeson.Types (ToJSON)+import Data.Maybe (catMaybes)+import Data.Text as T (Text, pack, replace, words)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.IO (readFile, writeFile)+import Data.Text.Lazy (fromStrict)+import Elm (Elm (..), prettyShowDecoder)+import Elm.Ast+import Elm.Generic (Elm (..))+import Elm.TyRep (EType, toElmType)+import Foreign (Int)+import GHC.Desugar (AnnotationWrapper)+import GHC.ExecutionStack (Location (functionName))+import GHC.Generics (Generic, to)+import Lens.Micro ((^.))+import Network.Wai ()+import Network.Wai.Handler.Warp (run)+import Servant (Application, Get, JSON, Proxy (Proxy), Server, serve)+import Servant.API+import Servant.Foreign+  ( GenerateList,+    HasForeign (Foreign),+    HasForeignType (..),+    PathSegment (unPathSegment),+    Req,+    Segment (unSegment),+    SegmentType (Cap, Static),+    camelCase,+    listFromAPI,+    path,+    reqFuncName,+    reqMethod,+    reqReturnType,+    reqUrl,+  )+import Text.PrettyPrint.Leijen.Text+  ( Doc,+    comma,+    dquotes,+    encloseSep,+    equals,+    hsep,+    indent,+    lbrace,+    lbracket,+    line,+    lparen,+    parens,+    pretty,+    punctuate,+    rbrace,+    rbracket,+    rparen,+    space,+    text,+    textStrict,+    vsep,+    (<$>),+    (<+>),+  )+import Prelude hiding ((<$>))++data LangElm++instance Elm a => HasForeignType LangElm ElmDefinition a where+  typeFor _ _ proxyA = toElmDefinition proxyA++elmForAPI ::+  ( HasForeign LangElm ElmDefinition api,+    GenerateList+      ElmDefinition+      (Foreign ElmDefinition api)+  ) =>+  Proxy api ->+  [Doc]+elmForAPI api =+  map endpointInfoToElmQuery $+    listFromAPI (Proxy :: Proxy LangElm) (Proxy :: Proxy ElmDefinition) api++elmRecord :: [Doc] -> Doc+elmRecord = encloseSep (lbrace <> space) (line <> rbrace) (comma <> space)++indent4Spaces :: Doc -> Doc+indent4Spaces = indent 4++endpointInfoToElmQuery :: Req ElmDefinition -> Doc+endpointInfoToElmQuery requestInfo =+  funcDef+  where+    funcDef =+      vsep+        [ fnName <+> ":" <+> typeSignature,+          fnName <+> args <+> equals,+          indent4Spaces elmRequest+        ]++    fnName = textStrict . camelCase $ requestInfo ^. reqFuncName++    typeSignature =+      mkTypeSignature requestInfo++    args =+      mkArgs requestInfo++    elmRequest =+      mkRequest requestInfo++elmList :: [Doc] -> Doc+elmList [] = lbracket <> rbracket+elmList ds = lbracket <+> hsep (punctuate (line <> comma) ds) <$> rbracket++stext :: Text -> Doc+stext = text . fromStrict++mkUrl :: [Segment ElmDefinition] -> Doc+mkUrl segments =+  urlBuilder+    <$> (indent4Spaces . elmList)+      (map segmentToDoc segments)+  where+    urlBuilder :: Doc+    urlBuilder = "Url.Builder.crossOrigin urlBase" :: Doc++    segmentToDoc :: Segment ElmDefinition -> Doc+    segmentToDoc s =+      case unSegment s of+        Static path ->+          dquotes (stext (unPathSegment path))+        Cap arg ->+          error+            "TODO implement-2" -- for captures, not needed now++elmTypeRefToDoc :: TypeRef -> Doc+elmTypeRefToDoc = \case+  RefPrim elmPrim -> elmPrimToDoc elmPrim+  RefCustom (TypeName typeName) -> pretty typeName++elmTypeParenDoc :: TypeRef -> Doc -- does it make sense to be a fn+elmTypeParenDoc = parens . elmTypeRefToDoc++elmPrimToDoc :: ElmPrim -> Doc+elmPrimToDoc = \case+  ElmUnit -> "()"+  ElmNever -> "Never"+  ElmBool -> "Bool"+  ElmChar -> "Char"+  ElmInt -> "Int"+  ElmFloat -> "Float"+  ElmString -> "String"+  ElmTime -> "Posix"+  ElmMaybe t -> "Maybe" <+> elmTypeParenDoc t+  ElmResult l r -> "Result" <+> elmTypeParenDoc l <+> elmTypeParenDoc r+  ElmPair a b -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> rparen+  ElmTriple a b c -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> comma <+> elmTypeRefToDoc c <> rparen+  ElmList l -> "List" <+> elmTypeParenDoc l++mkTypeSignature :: Req ElmDefinition -> Doc+mkTypeSignature request =+  (hsep . punctuate " ->") ("String" : catMaybes [toMsgType, returnType])+  where+    elmTypeRef :: ElmDefinition -> Doc+    elmTypeRef eDef = elmTypeRefToDoc (definitionToRef eDef)+    toMsgType :: Maybe Doc+    toMsgType = do+      result <- fmap elmTypeRef $ request ^. reqReturnType+      Just ("(Result Http.Error " <+> parens result <+> " -> msg)")++    returnType :: Maybe Doc+    returnType = do

Redundant do

MaggieVL

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}++module ServantElm+  ( elmForAPI,+  )+where++import Data.Aeson.Types (ToJSON)+import Data.Maybe (catMaybes)+import Data.Text as T (Text, pack, replace, words)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.IO (readFile, writeFile)+import Data.Text.Lazy (fromStrict)+import Elm (Elm (..), prettyShowDecoder)+import Elm.Ast+import Elm.Generic (Elm (..))+import Elm.TyRep (EType, toElmType)+import Foreign (Int)+import GHC.Desugar (AnnotationWrapper)+import GHC.ExecutionStack (Location (functionName))+import GHC.Generics (Generic, to)+import Lens.Micro ((^.))+import Network.Wai ()+import Network.Wai.Handler.Warp (run)+import Servant (Application, Get, JSON, Proxy (Proxy), Server, serve)+import Servant.API+import Servant.Foreign+  ( GenerateList,+    HasForeign (Foreign),+    HasForeignType (..),+    PathSegment (unPathSegment),+    Req,+    Segment (unSegment),+    SegmentType (Cap, Static),+    camelCase,+    listFromAPI,+    path,+    reqFuncName,+    reqMethod,+    reqReturnType,+    reqUrl,+  )+import Text.PrettyPrint.Leijen.Text+  ( Doc,+    comma,+    dquotes,+    encloseSep,+    equals,+    hsep,+    indent,+    lbrace,+    lbracket,+    line,+    lparen,+    parens,+    pretty,+    punctuate,+    rbrace,+    rbracket,+    rparen,+    space,+    text,+    textStrict,+    vsep,+    (<$>),+    (<+>),+  )+import Prelude hiding ((<$>))++data LangElm++instance Elm a => HasForeignType LangElm ElmDefinition a where+  typeFor _ _ proxyA = toElmDefinition proxyA++elmForAPI ::+  ( HasForeign LangElm ElmDefinition api,+    GenerateList+      ElmDefinition+      (Foreign ElmDefinition api)+  ) =>+  Proxy api ->+  [Doc]+elmForAPI api =+  map endpointInfoToElmQuery $+    listFromAPI (Proxy :: Proxy LangElm) (Proxy :: Proxy ElmDefinition) api++elmRecord :: [Doc] -> Doc+elmRecord = encloseSep (lbrace <> space) (line <> rbrace) (comma <> space)++indent4Spaces :: Doc -> Doc+indent4Spaces = indent 4++endpointInfoToElmQuery :: Req ElmDefinition -> Doc+endpointInfoToElmQuery requestInfo =+  funcDef+  where+    funcDef =+      vsep+        [ fnName <+> ":" <+> typeSignature,+          fnName <+> args <+> equals,+          indent4Spaces elmRequest+        ]++    fnName = textStrict . camelCase $ requestInfo ^. reqFuncName++    typeSignature =+      mkTypeSignature requestInfo++    args =+      mkArgs requestInfo++    elmRequest =+      mkRequest requestInfo++elmList :: [Doc] -> Doc+elmList [] = lbracket <> rbracket+elmList ds = lbracket <+> hsep (punctuate (line <> comma) ds) <$> rbracket++stext :: Text -> Doc+stext = text . fromStrict++mkUrl :: [Segment ElmDefinition] -> Doc+mkUrl segments =+  urlBuilder+    <$> (indent4Spaces . elmList)+      (map segmentToDoc segments)+  where+    urlBuilder :: Doc+    urlBuilder = "Url.Builder.crossOrigin urlBase" :: Doc++    segmentToDoc :: Segment ElmDefinition -> Doc+    segmentToDoc s =+      case unSegment s of+        Static path ->+          dquotes (stext (unPathSegment path))+        Cap arg ->+          error+            "TODO implement-2" -- for captures, not needed now++elmTypeRefToDoc :: TypeRef -> Doc+elmTypeRefToDoc = \case+  RefPrim elmPrim -> elmPrimToDoc elmPrim+  RefCustom (TypeName typeName) -> pretty typeName++elmTypeParenDoc :: TypeRef -> Doc -- does it make sense to be a fn+elmTypeParenDoc = parens . elmTypeRefToDoc++elmPrimToDoc :: ElmPrim -> Doc+elmPrimToDoc = \case+  ElmUnit -> "()"+  ElmNever -> "Never"+  ElmBool -> "Bool"+  ElmChar -> "Char"+  ElmInt -> "Int"+  ElmFloat -> "Float"+  ElmString -> "String"+  ElmTime -> "Posix"+  ElmMaybe t -> "Maybe" <+> elmTypeParenDoc t+  ElmResult l r -> "Result" <+> elmTypeParenDoc l <+> elmTypeParenDoc r+  ElmPair a b -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> rparen+  ElmTriple a b c -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> comma <+> elmTypeRefToDoc c <> rparen+  ElmList l -> "List" <+> elmTypeParenDoc l++mkTypeSignature :: Req ElmDefinition -> Doc+mkTypeSignature request =+  (hsep . punctuate " ->") ("String" : catMaybes [toMsgType, returnType])+  where+    elmTypeRef :: ElmDefinition -> Doc+    elmTypeRef eDef = elmTypeRefToDoc (definitionToRef eDef)+    toMsgType :: Maybe Doc+    toMsgType = do+      result <- fmap elmTypeRef $ request ^. reqReturnType+      Just ("(Result Http.Error " <+> parens result <+> " -> msg)")

You don't need the do block and the bind here, you can do it with a single fmap, I think

toMsgType = 
  fmap mkMsgType $ request ^. reqReturnType
  where
    mkMsgType x = ("(Result Http.Error " <+> parens (elmTypeRef x) <+> " -> msg)")

Also, try not to manually add spaces, like in "-> msg)"

MaggieVL

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}++module ServantElm+  ( elmForAPI,+  )+where++import Data.Aeson.Types (ToJSON)+import Data.Maybe (catMaybes)+import Data.Text as T (Text, pack, replace, words)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.IO (readFile, writeFile)+import Data.Text.Lazy (fromStrict)+import Elm (Elm (..), prettyShowDecoder)+import Elm.Ast+import Elm.Generic (Elm (..))+import Elm.TyRep (EType, toElmType)+import Foreign (Int)+import GHC.Desugar (AnnotationWrapper)+import GHC.ExecutionStack (Location (functionName))+import GHC.Generics (Generic, to)+import Lens.Micro ((^.))+import Network.Wai ()+import Network.Wai.Handler.Warp (run)+import Servant (Application, Get, JSON, Proxy (Proxy), Server, serve)+import Servant.API+import Servant.Foreign+  ( GenerateList,+    HasForeign (Foreign),+    HasForeignType (..),+    PathSegment (unPathSegment),+    Req,+    Segment (unSegment),+    SegmentType (Cap, Static),+    camelCase,+    listFromAPI,+    path,+    reqFuncName,+    reqMethod,+    reqReturnType,+    reqUrl,+  )+import Text.PrettyPrint.Leijen.Text+  ( Doc,+    comma,+    dquotes,+    encloseSep,+    equals,+    hsep,+    indent,+    lbrace,+    lbracket,+    line,+    lparen,+    parens,+    pretty,+    punctuate,+    rbrace,+    rbracket,+    rparen,+    space,+    text,+    textStrict,+    vsep,+    (<$>),+    (<+>),+  )+import Prelude hiding ((<$>))++data LangElm++instance Elm a => HasForeignType LangElm ElmDefinition a where+  typeFor _ _ proxyA = toElmDefinition proxyA++elmForAPI ::+  ( HasForeign LangElm ElmDefinition api,+    GenerateList+      ElmDefinition+      (Foreign ElmDefinition api)+  ) =>+  Proxy api ->+  [Doc]+elmForAPI api =+  map endpointInfoToElmQuery $+    listFromAPI (Proxy :: Proxy LangElm) (Proxy :: Proxy ElmDefinition) api++elmRecord :: [Doc] -> Doc+elmRecord = encloseSep (lbrace <> space) (line <> rbrace) (comma <> space)++indent4Spaces :: Doc -> Doc+indent4Spaces = indent 4++endpointInfoToElmQuery :: Req ElmDefinition -> Doc+endpointInfoToElmQuery requestInfo =+  funcDef+  where+    funcDef =+      vsep+        [ fnName <+> ":" <+> typeSignature,+          fnName <+> args <+> equals,+          indent4Spaces elmRequest+        ]++    fnName = textStrict . camelCase $ requestInfo ^. reqFuncName++    typeSignature =+      mkTypeSignature requestInfo++    args =+      mkArgs requestInfo++    elmRequest =+      mkRequest requestInfo++elmList :: [Doc] -> Doc+elmList [] = lbracket <> rbracket+elmList ds = lbracket <+> hsep (punctuate (line <> comma) ds) <$> rbracket++stext :: Text -> Doc+stext = text . fromStrict++mkUrl :: [Segment ElmDefinition] -> Doc+mkUrl segments =+  urlBuilder+    <$> (indent4Spaces . elmList)+      (map segmentToDoc segments)+  where+    urlBuilder :: Doc+    urlBuilder = "Url.Builder.crossOrigin urlBase" :: Doc++    segmentToDoc :: Segment ElmDefinition -> Doc+    segmentToDoc s =+      case unSegment s of+        Static path ->+          dquotes (stext (unPathSegment path))+        Cap arg ->+          error+            "TODO implement-2" -- for captures, not needed now++elmTypeRefToDoc :: TypeRef -> Doc+elmTypeRefToDoc = \case+  RefPrim elmPrim -> elmPrimToDoc elmPrim+  RefCustom (TypeName typeName) -> pretty typeName++elmTypeParenDoc :: TypeRef -> Doc -- does it make sense to be a fn+elmTypeParenDoc = parens . elmTypeRefToDoc++elmPrimToDoc :: ElmPrim -> Doc+elmPrimToDoc = \case+  ElmUnit -> "()"+  ElmNever -> "Never"+  ElmBool -> "Bool"+  ElmChar -> "Char"+  ElmInt -> "Int"+  ElmFloat -> "Float"+  ElmString -> "String"+  ElmTime -> "Posix"+  ElmMaybe t -> "Maybe" <+> elmTypeParenDoc t+  ElmResult l r -> "Result" <+> elmTypeParenDoc l <+> elmTypeParenDoc r+  ElmPair a b -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> rparen+  ElmTriple a b c -> lparen <> elmTypeRefToDoc a <> comma <+> elmTypeRefToDoc b <> comma <+> elmTypeRefToDoc c <> rparen+  ElmList l -> "List" <+> elmTypeParenDoc l++mkTypeSignature :: Req ElmDefinition -> Doc+mkTypeSignature request =+  (hsep . punctuate " ->") ("String" : catMaybes [toMsgType, returnType])

You should usually not be manually inserting spaces in strings when using a pretty printer, like in " ->" - shouldn't hsep already be taking care to put the spaces anyway?

MaggieVL

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}++module ServantElm+  ( elmForAPI,+  )+where++import Data.Aeson.Types (ToJSON)+import Data.Maybe (catMaybes)+import Data.Text as T (Text, pack, replace, words)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.IO (readFile, writeFile)+import Data.Text.Lazy (fromStrict)+import Elm (Elm (..), prettyShowDecoder)+import Elm.Ast+import Elm.Generic (Elm (..))+import Elm.TyRep (EType, toElmType)+import Foreign (Int)+import GHC.Desugar (AnnotationWrapper)+import GHC.ExecutionStack (Location (functionName))+import GHC.Generics (Generic, to)+import Lens.Micro ((^.))+import Network.Wai ()+import Network.Wai.Handler.Warp (run)+import Servant (Application, Get, JSON, Proxy (Proxy), Server, serve)+import Servant.API+import Servant.Foreign+  ( GenerateList,+    HasForeign (Foreign),+    HasForeignType (..),+    PathSegment (unPathSegment),+    Req,+    Segment (unSegment),+    SegmentType (Cap, Static),+    camelCase,+    listFromAPI,+    path,+    reqFuncName,+    reqMethod,+    reqReturnType,+    reqUrl,+  )+import Text.PrettyPrint.Leijen.Text+  ( Doc,+    comma,+    dquotes,+    encloseSep,+    equals,+    hsep,+    indent,+    lbrace,+    lbracket,+    line,+    lparen,+    parens,+    pretty,+    punctuate,+    rbrace,+    rbracket,+    rparen,+    space,+    text,+    textStrict,+    vsep,+    (<$>),+    (<+>),+  )+import Prelude hiding ((<$>))++data LangElm++instance Elm a => HasForeignType LangElm ElmDefinition a where+  typeFor _ _ proxyA = toElmDefinition proxyA++elmForAPI ::+  ( HasForeign LangElm ElmDefinition api,+    GenerateList+      ElmDefinition+      (Foreign ElmDefinition api)+  ) =>+  Proxy api ->+  [Doc]+elmForAPI api =+  map endpointInfoToElmQuery $+    listFromAPI (Proxy :: Proxy LangElm) (Proxy :: Proxy ElmDefinition) api++elmRecord :: [Doc] -> Doc+elmRecord = encloseSep (lbrace <> space) (line <> rbrace) (comma <> space)++indent4Spaces :: Doc -> Doc+indent4Spaces = indent 4++endpointInfoToElmQuery :: Req ElmDefinition -> Doc+endpointInfoToElmQuery requestInfo =+  funcDef+  where+    funcDef =+      vsep+        [ fnName <+> ":" <+> typeSignature,+          fnName <+> args <+> equals,+          indent4Spaces elmRequest+        ]++    fnName = textStrict . camelCase $ requestInfo ^. reqFuncName++    typeSignature =+      mkTypeSignature requestInfo++    args =+      mkArgs requestInfo++    elmRequest =+      mkRequest requestInfo++elmList :: [Doc] -> Doc+elmList [] = lbracket <> rbracket+elmList ds = lbracket <+> hsep (punctuate (line <> comma) ds) <$> rbracket++stext :: Text -> Doc+stext = text . fromStrict++mkUrl :: [Segment ElmDefinition] -> Doc+mkUrl segments =+  urlBuilder+    <$> (indent4Spaces . elmList)+      (map segmentToDoc segments)+  where+    urlBuilder :: Doc+    urlBuilder = "Url.Builder.crossOrigin urlBase" :: Doc++    segmentToDoc :: Segment ElmDefinition -> Doc+    segmentToDoc s =+      case unSegment s of+        Static path ->+          dquotes (stext (unPathSegment path))+        Cap arg ->+          error+            "TODO implement-2" -- for captures, not needed now++elmTypeRefToDoc :: TypeRef -> Doc+elmTypeRefToDoc = \case+  RefPrim elmPrim -> elmPrimToDoc elmPrim+  RefCustom (TypeName typeName) -> pretty typeName++elmTypeParenDoc :: TypeRef -> Doc -- does it make sense to be a fn

Why not? It's used more than once, so it seems fine to have this.

MaggieVL

comment created time in 4 days

Pull request review commentChaosGroup/servant-elm-street

Handle simple get requests

+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}++module ServantElm+  ( elmForAPI,+  )+where++import Data.Aeson.Types (ToJSON)+import Data.Maybe (catMaybes)+import Data.Text as T (Text, pack, replace, words)+import Data.Text.Encoding (decodeUtf8)+import Data.Text.IO (readFile, writeFile)+import Data.Text.Lazy (fromStrict)+import Elm (Elm (..), prettyShowDecoder)+import Elm.Ast+import Elm.Generic (Elm (..))+import Elm.TyRep (EType, toElmType)+import Foreign (Int)+import GHC.Desugar (AnnotationWrapper)+import GHC.ExecutionStack (Location (functionName))+import GHC.Generics (Generic, to)+import Lens.Micro ((^.))+import Network.Wai ()+import Network.Wai.Handler.Warp (run)+import Servant (Application, Get, JSON, Proxy (Proxy), Server, serve)+import Servant.API+import Servant.Foreign+  ( GenerateList,+    HasForeign (Foreign),+    HasForeignType (..),+    PathSegment (unPathSegment),+    Req,+    Segment (unSegment),+    SegmentType (Cap, Static),+    camelCase,+    listFromAPI,+    path,+    reqFuncName,+    reqMethod,+    reqReturnType,+    reqUrl,+  )+import Text.PrettyPrint.Leijen.Text+  ( Doc,+    comma,+    dquotes,+    encloseSep,+    equals,+    hsep,+    indent,+    lbrace,+    lbracket,+    line,+    lparen,+    parens,+    pretty,+    punctuate,+    rbrace,+    rbracket,+    rparen,+    space,+    text,+    textStrict,+    vsep,+    (<$>),+    (<+>),+  )+import Prelude hiding ((<$>))++data LangElm++instance Elm a => HasForeignType LangElm ElmDefinition a where+  typeFor _ _ proxyA = toElmDefinition proxyA++elmForAPI ::+  ( HasForeign LangElm ElmDefinition api,+    GenerateList+      ElmDefinition+      (Foreign ElmDefinition api)+  ) =>+  Proxy api ->+  [Doc]+elmForAPI api =+  map endpointInfoToElmQuery $+    listFromAPI (Proxy :: Proxy LangElm) (Proxy :: Proxy ElmDefinition) api++elmRecord :: [Doc] -> Doc+elmRecord = encloseSep (lbrace <> space) (line <> rbrace) (comma <> space)++indent4Spaces :: Doc -> Doc+indent4Spaces = indent 4++endpointInfoToElmQuery :: Req ElmDefinition -> Doc+endpointInfoToElmQuery requestInfo =+  funcDef+  where+    funcDef =+      vsep+        [ fnName <+> ":" <+> typeSignature,+          fnName <+> args <+> equals,+          indent4Spaces elmRequest+        ]++    fnName = textStrict . camelCase $ requestInfo ^. reqFuncName++    typeSignature =+      mkTypeSignature requestInfo++    args =+      mkArgs requestInfo++    elmRequest =+      mkRequest requestInfo++elmList :: [Doc] -> Doc+elmList [] = lbracket <> rbracket+elmList ds = lbracket <+> hsep (punctuate (line <> comma) ds) <$> rbracket++stext :: Text -> Doc+stext = text . fromStrict++mkUrl :: [Segment ElmDefinition] -> Doc+mkUrl segments =+  urlBuilder+    <$> (indent4Spaces . elmList)+      (map segmentToDoc segments)+  where+    urlBuilder :: Doc+    urlBuilder = "Url.Builder.crossOrigin urlBase" :: Doc++    segmentToDoc :: Segment ElmDefinition -> Doc+    segmentToDoc s =+      case unSegment s of+        Static path ->+          dquotes (stext (unPathSegment path))+        Cap arg ->+          error+            "TODO implement-2" -- for captures, not needed now

Just put the comment inside the error, no point in having some other text in the error which isn't very informative.

MaggieVL

comment created time in 4 days

PullRequestReviewEvent
more