elm-syntax 0.3.0.0 → 0.3.3.0
raw patch · 6 files changed
Files
- CHANGELOG.md +13/−1
- README.md +1/−1
- elm-syntax.cabal +11/−10
- src/Language/Elm/Expression.hs +43/−5
- src/Language/Elm/Pretty.hs +16/−5
- src/Language/Elm/Simplification.hs +5/−0
CHANGELOG.md view
@@ -1,6 +1,18 @@ # Changelog for elm-syntax -## Unreleased changes+## 0.3.3.0++- Add support for GHC up to 9.6++## 0.3.2.0++- The `Monad` instance for `Expression` has been redefined, leading to considerably faster performance. (see [#4](https://github.com/haskell-to-elm/elm-syntax/pull/4))++## 0.3.1.0++- Simplify record projections on known records+- Write explicit export lists+- Fix build with GHC 9.0. (see [#2](https://github.com/haskell-to-elm/elm-syntax/pull/2)) ## 0.3.0.0
README.md view
@@ -1,4 +1,4 @@-# elm-syntax [](https://travis-ci.com/folq/elm-syntax) [](https://hackage.haskell.org/package/elm-syntax)+# elm-syntax [](https://hackage.haskell.org/package/elm-syntax) A library for generating Elm syntax from Haskell in a scope-safe way.
elm-syntax.cabal view
@@ -1,24 +1,25 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack ----- hash: 7a5a97356a0303c135c29af83618eccb2a2d5844234020ab4cd4f38ee561609d+-- hash: a3e365d3cf561f985813175da49dc02d42f3493a20c53389969c4b15f3e4f5c4 name: elm-syntax-version: 0.3.0.0+version: 0.3.3.0 synopsis: Elm syntax and pretty-printing-description: Please see the README on GitHub at <https://github.com/folq/elm-syntax#readme>+description: Please see the README on GitHub at <https://github.com/haskell-to-elm/elm-syntax#readme> category: Elm, Compiler, Language-homepage: https://github.com/folq/elm-syntax#readme-bug-reports: https://github.com/folq/elm-syntax/issues+homepage: https://github.com/haskell-to-elm/elm-syntax#readme+bug-reports: https://github.com/haskell-to-elm/elm-syntax/issues author: Olle Fredriksson maintainer: fredriksson.olle@gmail.com copyright: 2019 Olle Fredriksson license: BSD3 license-file: LICENSE-tested-with: GHC == 8.4.3, GHC == 8.6.5, GHC == 8.8.3+tested-with:+ GHC == 8.4.3, GHC == 8.6.5, GHC == 8.8.3, GHC == 9.2.5 build-type: Simple extra-source-files: README.md@@ -26,7 +27,7 @@ source-repository head type: git- location: https://github.com/folq/elm-syntax+ location: https://github.com/haskell-to-elm/elm-syntax library exposed-modules:@@ -47,7 +48,7 @@ , bound >=2.0.0 , deriving-compat >=0.5.0 , hashable >=1.2.5- , prettyprinter >=1.2.1+ , prettyprinter >=1.6.0 , text >=1.2.0 , unordered-containers >=0.2.8 default-language: Haskell2010@@ -66,7 +67,7 @@ , deriving-compat >=0.5.0 , elm-syntax , hashable >=1.2.5- , prettyprinter >=1.2.1+ , prettyprinter >=1.6.0 , text >=1.2.0 , unordered-containers >=0.2.8 default-language: Haskell2010
src/Language/Elm/Expression.hs view
@@ -7,6 +7,7 @@ {-# language ScopedTypeVariables #-} {-# language StandaloneDeriving #-} {-# language TemplateHaskell #-}+{-# language TupleSections #-} module Language.Elm.Expression where import Bound@@ -44,9 +45,45 @@ (<*>) = ap instance Monad Expression where- (>>=) =- flip $ bind Global+ expression >>= f =+ case expression of+ Var v ->+ f v + Global g ->+ Global g+ + App g x ->+ App (g >>= f) (x >>= f)++ Let e s ->+ Let (e >>= f) (s >>>= f)++ Lam e -> + Lam (e >>>= f)++ Record fields ->+ Record (map (fmap (>>= f)) fields)+ + Proj fieldName ->+ Proj fieldName++ Case e patterns ->+ Case (e >>= f) (map (fmap (>>>= f)) patterns)+ + List es -> + List (map (>>= f) es)++ String text ->+ String text++ Int integer -> + Int integer++ Float double -> + Float double++ bind :: forall v v'. (Name.Qualified -> Expression v') -> (v -> Expression v') -> Expression v -> Expression v' bind global var expression = case expression of@@ -94,13 +131,14 @@ bind (fmap F . global) (unvar (pure . B) (fmap F . var)) . fromScope +deriveEq1 ''Expression deriving instance Eq v => Eq (Expression v)-deriving instance Ord v => Ord (Expression v)-deriving instance Show v => Show (Expression v) -deriveEq1 ''Expression deriveOrd1 ''Expression+deriving instance Ord v => Ord (Expression v)+ deriveShow1 ''Expression+deriving instance Show v => Show (Expression v) instance IsString (Expression v) where fromString = Global . fromString
src/Language/Elm/Pretty.hs view
@@ -1,3 +1,4 @@+{-# language LambdaCase #-} {-# language OverloadedStrings #-} {-# language ViewPatterns #-} module Language.Elm.Pretty@@ -35,7 +36,7 @@ import Data.List (sort, intersperse) import Data.Maybe (isNothing) import Data.String-import Data.Text.Prettyprint.Doc+import Prettyprinter import Data.Void import Language.Elm.Definition (Definition)@@ -92,8 +93,21 @@ HashSet.map (\(Name.Qualified m _) -> m) $ HashSet.filter (isNothing . defaultImport) $ foldMap (Definition.foldMapGlobals HashSet.singleton) defs++ exports =+ indent 4 $+ (<> line <> ")") $+ vsep $+ zipWith (<>) ("( " : repeat ", ") $+ map export defs++ export = \case+ Definition.Constant (Name.Qualified _ name) _ _ _ -> pretty name+ Definition.Type (Name.Qualified _ name) _ _ -> pretty name <> "(..)"+ Definition.Alias (Name.Qualified _ name) _ _ -> pretty name+ in- "module" <+> moduleName mname <+> "exposing (..)" <> line <> line <>+ "module" <+> moduleName mname <+> "exposing" <> line <> exports <> line <> line <> mconcat ["import" <+> moduleName import_ <> line | import_ <- imports] <> line <> line <> mconcat (intersperse (line <> line <> line) [definition env def | def <- defs]) @@ -291,9 +305,6 @@ Name.Qualified ["Parser"] "|." -> leftAssoc 6-- "Basics.++" ->- rightAssoc 5 "Basics.++" -> rightAssoc 5
src/Language/Elm/Simplification.hs view
@@ -69,6 +69,7 @@ -- is simplified to @let xs = es in branch@ provided that @e@ matches none of -- @prefixBranches@ and that it matches @pat@. -- * case-of-case+-- * { n = e, ... }.n = e -- simplifyExpression :: Expression v@@ -129,6 +130,10 @@ (Expression.Global _, _) -> Expression.apps expr args++ (Expression.Proj field, Expression.Record record:args')+ | Just e <- lookup field record ->+ simplifyApplication e args' (Expression.App e1 e2, _) -> simplifyApplication e1 (simplifyExpression e2 : args)