on master help sign in
added lists
commitc9ac6ac176f5b59f54c99706cba5f63ce796e8cb authoriko <ilyakooo0@gmail.com> dateTue 26 Jul 2022, 17:22 (4 years ago) parent6499c28
3 files changed+59−6
elm-ps-bridge.cabal+1 package.yaml+11 src/Main.hs+47−6
elm-ps-bridge.cabal+1
@@ -57,6 +57,7 @@ executable elm-ps-bridge
5757 TypeOperators
5858 UndecidableInstances
5959 ViewPatterns
60+ ghc-options: -Weverything -Wno-implicit-prelude -Wno-missing-safe-haskell-mode -Wno-safe -Wno-prepositive-qualified-module -Wno-missing-import-lists -Wno-all-missed-specialisations -Wno-missing-local-signatures -Wno-partial-fields -Wno-unsafe -Wno-monomorphism-restriction -Wno-missed-specialisations -Wno-partial-type-signatures -Wno-unticked-promoted-constructors -Wno-incomplete-uni-patterns -Wno-missing-kind-signatures -fexpose-all-unfoldings -fspecialise-aggressively -O0 -threaded -rtsopts -with-rtsopts=-N
6061 build-depends:
6162 aeson
6263 , base
package.yaml+11
@@ -61,3 +61,14 @@ default-extensions:
6161 - TypeOperators
6262 - UndecidableInstances
6363 - ViewPatterns
64+
65+ghc-options:
66+ -Weverything -Wno-implicit-prelude -Wno-missing-safe-haskell-mode
67+ -Wno-safe -Wno-prepositive-qualified-module
68+ -Wno-missing-import-lists -Wno-all-missed-specialisations
69+ -Wno-missing-local-signatures -Wno-partial-fields -Wno-unsafe
70+ -Wno-monomorphism-restriction -Wno-missed-specialisations
71+ -Wno-partial-type-signatures -Wno-unticked-promoted-constructors
72+ -Wno-incomplete-uni-patterns -Wno-missing-kind-signatures
73+ -fexpose-all-unfoldings -fspecialise-aggressively -O0 -threaded
74+ -rtsopts -with-rtsopts=-N
src/Main.hs+47−6
@@ -2,10 +2,8 @@ module Main (main) where
22
33import Control.Monad.Writer.Strict
44import Data.Aeson hiding (Options)
5−import Data.Aeson.Types (Parser)
65import Data.HashMap.Strict qualified as HM
76import Data.Map.Lazy qualified as M
8−import Data.Text qualified as T
97import Data.Vector (Vector)
108import Data.Vector qualified as V
119import Data.Yaml as Yaml
@@ -70,10 +68,25 @@ elm datattypes =
7068 in makeElmModuleFromETypeDef "Bridge" types
7169
7270elmType :: Text -> Datatype -> Writer [ETypeDef] EType
73−elmType name BoolType = pure $ ETyCon $ ETCon "Bool"
74−elmType name IntType = pure $ ETyCon $ ETCon "Int"
75−elmType name FloatType = pure $ ETyCon $ ETCon "Float"
76−elmType name StringType = pure $ ETyCon $ ETCon "String"
71+elmType _ BoolType = pure $ ETyCon $ ETCon "Bool"
72+elmType _ IntType = pure $ ETyCon $ ETCon "Int"
73+elmType _ FloatType = pure $ ETyCon $ ETCon "Float"
74+elmType _ StringType = pure $ ETyCon $ ETCon "String"
75+elmType name (List inner) = do
76+ -- fields' <- traverse (\(k, v) -> (toString k,) <$> elmType (name <> "_" <> k) v) $ M.toList fields
77+ inner' <- elmType name inner
78+ tell
79+ [ ETypePrimAlias
80+ EPrimAlias
81+ { epa_name =
82+ ETypeName
83+ { et_name = toString name <> "_List",
84+ et_args = []
85+ },
86+ epa_type = ETyApp (ETyCon (ETCon "List")) inner'
87+ }
88+ ]
89+ pure $ ETyCon $ ETCon $ toString name
7790elmType name (ProductType fields) = do
7891 fields' <- traverse (\(k, v) -> (toString k,) <$> elmType (name <> "_" <> k) v) $ M.toList fields
7992 tell
@@ -125,6 +138,34 @@ psType _ BoolType = pure psBool
125138psType _ IntType = pure psInt
126139psType _ FloatType = pure psNumber
127140psType _ StringType = pure psString
141+psType name (List inner) = do
142+ inner' <- psType name inner
143+ let ti =
144+ TypeInfo
145+ { _typePackage = "bridge",
146+ _typeModule = "Bridge",
147+ _typeName = name <> "_List",
148+ _typeParameters = []
149+ }
150+ tell
151+ [ PS.SumType
152+ ti
153+ [ DataConstructor
154+ { _sigConstructor = name <> "_List",
155+ _sigValues =
156+ Left
157+ [ TypeInfo
158+ { _typePackage = "builtins",
159+ _typeModule = "Prim",
160+ _typeName = "Array",
161+ _typeParameters = [inner']
162+ }
163+ ]
164+ }
165+ ]
166+ allInstances
167+ ]
168+ pure ti
128169psType name (SumDatatype (SumType sums)) = do
129170 sums' <- traverse (\(k, v) -> (k,) <$> traverse (psType (name <> "_" <> k)) v) $ M.toList sums
130171 let ti =