Last active
October 22, 2020 01:16
-
-
Save paulyoung/7e51897c612c1ff13a6f1aad7b71e5b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Control.Monad.Except (runExcept) | |
import Data.Either (Either(..)) | |
import Data.Maybe (Maybe(..)) | |
import Effect.Console (log, logShow) | |
import Foreign (F) | |
import Foreign.Generic (defaultOptions, genericDecodeJSON, genericEncodeJSON) | |
import TryPureScript (render, withConsole) | |
main = render =<< withConsole do | |
-- {"contents":1,"tag":"Just"} | |
log $ genericEncodeJSON defaultOptions $ Just 1 | |
-- Right (Just 1) | |
logShow $ runExcept (genericDecodeJSON defaultOptions "{\"contents\":1,\"tag\":\"Just\"}" :: F (Maybe Int)) | |
-- The inferred type | |
-- | |
-- forall t33 t39. Generic (Either String Int) t33 => GenericEncode t33 => GenericEncode t39 => Effect Unit | |
-- | |
-- has type variables which are not determined by those mentioned in the body of the type: | |
-- | |
-- t39 could not be determined | |
-- | |
-- Consider adding a type annotation. | |
log $ genericEncodeJSON defaultOptions (Left "Something went wrong" :: Either String Int) | |
log $ genericEncodeJSON defaultOptions (Right 1 :: Either String Int) | |
-- The inferred type | |
-- | |
-- forall t46 t53. Generic (Either String Int) t46 => GenericDecode t46 => GenericDecode t53 => Effect Unit | |
-- | |
-- has type variables which are not determined by those mentioned in the body of the type: | |
-- | |
-- t53 could not be determined | |
-- | |
-- Consider adding a type annotation. | |
logShow $ runExcept (genericDecodeJSON defaultOptions "{\"contents\":1,\"tag\":\"Right\"}" :: F (Either String Int)) | |
logShow $ runExcept (genericDecodeJSON defaultOptions "{\"contents\":\"Something went wrong\",\"tag\":\"Left\"}" :: F (Either String Int)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment