on master help sign in
Things now actually work!
commit6499c2806ff16e68cb5ca63793fa22a701dcdcd8 authoriko <ilyakooo0@gmail.com> dateSat 23 Jul 2022, 15:55 (4 years ago) parente922092
4 files changed+92−8
elm-ps-bridge.cabal+74 package.yaml+3 src/Main.hs+10−7 stack.yaml+5−1
elm-ps-bridge.cabalnew file+74
@@ -0,0 +1,74 @@
1+cabal-version: 1.12
2+
3+-- This file has been generated from package.yaml by hpack version 0.34.4.
4+--
5+-- see: https://github.com/sol/hpack
6+
7+name: elm-ps-bridge
8+version: 0.0.0
9+license: MIT
10+license-file: LICENSE
11+build-type: Simple
12+
13+executable elm-ps-bridge
14+ main-is: Main.hs
15+ other-modules:
16+ Elm
17+ Paths_elm_ps_bridge
18+ hs-source-dirs:
19+ src
20+ default-extensions:
21+ NoImplicitPrelude
22+ AllowAmbiguousTypes
23+ ApplicativeDo
24+ BangPatterns
25+ BlockArguments
26+ ConstraintKinds
27+ DataKinds
28+ DefaultSignatures
29+ DeriveAnyClass
30+ DeriveFunctor
31+ DeriveGeneric
32+ DerivingVia
33+ DuplicateRecordFields
34+ FlexibleContexts
35+ FlexibleInstances
36+ FunctionalDependencies
37+ GADTs
38+ GeneralizedNewtypeDeriving
39+ ImportQualifiedPost
40+ LambdaCase
41+ MonoLocalBinds
42+ MultiParamTypeClasses
43+ NamedFieldPuns
44+ OverloadedLabels
45+ OverloadedStrings
46+ PartialTypeSignatures
47+ PolyKinds
48+ RankNTypes
49+ RecordWildCards
50+ RecursiveDo
51+ ScopedTypeVariables
52+ StandaloneDeriving
53+ StandaloneKindSignatures
54+ TupleSections
55+ TypeApplications
56+ TypeFamilies
57+ TypeOperators
58+ UndecidableInstances
59+ ViewPatterns
60+ build-depends:
61+ aeson
62+ , base
63+ , bytestring
64+ , containers
65+ , elm-bridge
66+ , mtl
67+ , optparse-generic
68+ , purescript-bridge
69+ , relude
70+ , text
71+ , unordered-containers
72+ , vector
73+ , yaml
74+ default-language: Haskell2010
package.yaml+3
@@ -13,6 +13,9 @@ dependencies:
1313 - aeson
1414 - elm-bridge
1515 - mtl
16+ - containers
17+ - text
18+ - unordered-containers
1619
1720executable:
1821 main: Main.hs
src/Main.hs+10−7
@@ -2,10 +2,10 @@ module Main (main) where
22
33import Control.Monad.Writer.Strict
44import Data.Aeson hiding (Options)
5−import Data.Aeson.Key qualified as Key
6−import Data.Aeson.KeyMap qualified as KeyMap
75import Data.Aeson.Types (Parser)
6+import Data.HashMap.Strict qualified as HM
87import Data.Map.Lazy qualified as M
8+import Data.Text qualified as T
99import Data.Vector (Vector)
1010import Data.Vector qualified as V
1111import Data.Yaml as Yaml
@@ -32,6 +32,7 @@ data Datatype
3232 | IntType
3333 | FloatType
3434 | StringType
35+ | List Datatype
3536 deriving stock (Show)
3637
3738newtype SumType = SumType (Map Text (Maybe Datatype))
@@ -41,13 +42,14 @@ parseSumType :: Vector Value -> Parser SumType
4142parseSumType = fmap (SumType . fold) . traverse parseConstructor . V.toList
4243 where
4344 parseConstructor (String s) = pure $ one (s, Nothing)
44− parseConstructor (Object o) | [(Key.toText -> k, v)] <- KeyMap.toList o = one . (k,) . Just <$> parseJSON v
45+ parseConstructor (Object o) | [(k, v)] <- HM.toList o = one . (k,) . Just <$> parseJSON v
4546 parseConstructor (Object _) = fail "Sum types can only have one name per constructor"
4647 parseConstructor _ = fail "Sum Bad sum type ;("
4748
4849instance FromJSON Datatype where
4950 parseJSON (Array a) = SumDatatype <$> parseSumType a
50− parseJSON (Object o) = ProductType <$> traverse parseJSON (M.mapKeysMonotonic Key.toText $ KeyMap.toMap o)
51+ parseJSON (Object o) | [("List", x)] <- HM.toList o = List <$> parseJSON x
52+ parseJSON (Object o) = ProductType <$> traverse parseJSON (M.fromList $ HM.toList o)
5153 parseJSON (String "Bool") = pure BoolType
5254 parseJSON (String "Int") = pure IntType
5355 parseJSON (String "Float") = pure FloatType
@@ -112,7 +114,7 @@ elmType name (SumDatatype (SumType sums)) = do
112114 SumEncoding'
113115 TaggedObject
114116 { tagFieldName = "tag",
115− contentsFieldName = "values"
117+ contentsFieldName = "contents"
116118 }
117119 }
118120 ]
@@ -173,8 +175,8 @@ psType name (ProductType fields) = do
173175
174176allInstances :: [PS.Instance]
175177allInstances =
176− [ PS.Encode,
177− PS.Decode,
178+ [ PS.EncodeJson,
179+ PS.DecodeJson,
178180 PS.Generic,
179181 PS.Eq,
180182 PS.Ord
@@ -187,6 +189,7 @@ ps datattypes =
187189 PSS.Settings
188190 { generateLenses = False,
189191 genericsGenRep = True,
192+ generateArgonautCodecs = True,
190193 generateForeign = Nothing
191194 }
192195 PSModule
stack.yaml+5−1
@@ -1,4 +1,8 @@
1−resolver: lts-19.16
1+resolver: lts-18.28
22
33packages:
44- .
5+
6+extra-deps:
7+- git: https://github.com/eskimor/purescript-bridge.git
8+ commit: a65fd634730adc81eebf09f1e490342dda4cacb2