AlternativeMain, to test stuff (currently sum types JSON encoding).

master
Philippe Pittoli 9 months ago
parent bc5c7d3fde
commit a51b943f84

@ -1,6 +1,7 @@
{ name = "halogen-project"
, dependencies =
[ "aff"
, "argonaut-codecs"
, "argonaut-core"
, "arraybuffer"
, "arraybuffer-builder"

@ -0,0 +1,41 @@
-- | To run this alternative main: spago run -m AlternativeMain
module AlternativeMain where
import Prelude
import Effect (Effect)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Class.Console as Console
import Data.Argonaut.Core as J
import Data.Codec.Argonaut as CA
import Data.Maybe (Maybe)
import Data.Argonaut.Decode as DAD
import Data.Either (Either(..))
import Data.Codec.Argonaut.Record as CAR
import Data.UInt (fromInt, toInt, UInt)
import Data.Argonaut.Parser as JSONParser
import Data.Bifunctor (lmap)
import Data.Tuple (Tuple(..))
import App.PermissionLevel as PermissionLevel
type SumType = { permission :: PermissionLevel.PermissionLevel }
codecSumType = CA.object "SumType" (CAR.record { permission: PermissionLevel.codec })
encode :: SumType -> String
encode = J.stringify <<< CA.encode codecSumType
decode :: String -> Either String SumType
decode = parseDecodeJSON codecSumType
parseDecodeJSON :: forall a. CA.JsonCodec a -> String -> Either String a
parseDecodeJSON codec str = do
json <- JSONParser.jsonParser str
lmap CA.printJsonDecodeError (CA.decode codec json)
main :: Effect Unit
main = do
Console.log ("Hello this is the main")
let origin = { permission: PermissionLevel.Read }
Console.log ("origin: " <> encode origin)
Loading…
Cancel
Save