Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,25 @@ is either a JSON boolean or the JSON ``null``.

To validate a JSON value using Medea from Haskell:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean 'PureScript' right?


```Haskell
import Control.Monad.Trans.Except (runExcept, runExceptT)
import Data.Aeson (Value)
```Purescript
import Prelude
import Effect (Effect)
import Effect.Log (log)
import Control.Monad.Except.Trans (runExceptT)
import Control.Monad.Except (runExcept)
import Data.Argonaut (Json)
import Data.Medea.Loader (loadSchemaFromFile)
import Data.Medea (validate)

main :: IO ()
main :: Effect Unit
main = do
-- Compile a Medea schema graph from its file representation
result <- runExceptT . loadSchemaFromFile $ "./my-schema.medea"
case result of
Left e -> print e
Left e -> log e
Right scm -> do
-- Validate against the schema graph we just compiled
validation <- runExcept $ validate scm (myJson :: Value)
validation <- runExcept $ validate scm (myJson :: Json)
case validation of
Left e -> print e
Right _ -> putStrLn "JSON is valid against schema"
Expand Down