{-# LANGUAGE TemplateHaskell #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
module Swarm.Language.Typed (Typed (..), value, polytype, requires) where

import Control.Lens (makeLenses)
import Data.Aeson (ToJSON)
import Data.Aeson.Types (FromJSON)
import GHC.Generics (Generic)
import Swarm.Language.Requirements.Type (Requirements)
import Swarm.Language.Types (Polytype)

-- | A value, or a hole, or something else that has its type & requirements fixed
data Typed v = Typed
  { forall v. Typed v -> v
_value :: v
  , forall v. Typed v -> Polytype
_polytype :: Polytype
  , forall v. Typed v -> Requirements
_requires :: Requirements
  }
  deriving (Int -> Typed v -> ShowS
[Typed v] -> ShowS
Typed v -> String
(Int -> Typed v -> ShowS)
-> (Typed v -> String) -> ([Typed v] -> ShowS) -> Show (Typed v)
forall v. Show v => Int -> Typed v -> ShowS
forall v. Show v => [Typed v] -> ShowS
forall v. Show v => Typed v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall v. Show v => Int -> Typed v -> ShowS
showsPrec :: Int -> Typed v -> ShowS
$cshow :: forall v. Show v => Typed v -> String
show :: Typed v -> String
$cshowList :: forall v. Show v => [Typed v] -> ShowS
showList :: [Typed v] -> ShowS
Show, Typed v -> Typed v -> Bool
(Typed v -> Typed v -> Bool)
-> (Typed v -> Typed v -> Bool) -> Eq (Typed v)
forall v. Eq v => Typed v -> Typed v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall v. Eq v => Typed v -> Typed v -> Bool
== :: Typed v -> Typed v -> Bool
$c/= :: forall v. Eq v => Typed v -> Typed v -> Bool
/= :: Typed v -> Typed v -> Bool
Eq, (forall x. Typed v -> Rep (Typed v) x)
-> (forall x. Rep (Typed v) x -> Typed v) -> Generic (Typed v)
forall x. Rep (Typed v) x -> Typed v
forall x. Typed v -> Rep (Typed v) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall v x. Rep (Typed v) x -> Typed v
forall v x. Typed v -> Rep (Typed v) x
$cfrom :: forall v x. Typed v -> Rep (Typed v) x
from :: forall x. Typed v -> Rep (Typed v) x
$cto :: forall v x. Rep (Typed v) x -> Typed v
to :: forall x. Rep (Typed v) x -> Typed v
Generic, Maybe (Typed v)
Value -> Parser [Typed v]
Value -> Parser (Typed v)
(Value -> Parser (Typed v))
-> (Value -> Parser [Typed v])
-> Maybe (Typed v)
-> FromJSON (Typed v)
forall v. FromJSON v => Maybe (Typed v)
forall v. FromJSON v => Value -> Parser [Typed v]
forall v. FromJSON v => Value -> Parser (Typed v)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: forall v. FromJSON v => Value -> Parser (Typed v)
parseJSON :: Value -> Parser (Typed v)
$cparseJSONList :: forall v. FromJSON v => Value -> Parser [Typed v]
parseJSONList :: Value -> Parser [Typed v]
$comittedField :: forall v. FromJSON v => Maybe (Typed v)
omittedField :: Maybe (Typed v)
FromJSON, [Typed v] -> Value
[Typed v] -> Encoding
Typed v -> Bool
Typed v -> Value
Typed v -> Encoding
(Typed v -> Value)
-> (Typed v -> Encoding)
-> ([Typed v] -> Value)
-> ([Typed v] -> Encoding)
-> (Typed v -> Bool)
-> ToJSON (Typed v)
forall v. ToJSON v => [Typed v] -> Value
forall v. ToJSON v => [Typed v] -> Encoding
forall v. ToJSON v => Typed v -> Bool
forall v. ToJSON v => Typed v -> Value
forall v. ToJSON v => Typed v -> Encoding
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: forall v. ToJSON v => Typed v -> Value
toJSON :: Typed v -> Value
$ctoEncoding :: forall v. ToJSON v => Typed v -> Encoding
toEncoding :: Typed v -> Encoding
$ctoJSONList :: forall v. ToJSON v => [Typed v] -> Value
toJSONList :: [Typed v] -> Value
$ctoEncodingList :: forall v. ToJSON v => [Typed v] -> Encoding
toEncodingList :: [Typed v] -> Encoding
$comitField :: forall v. ToJSON v => Typed v -> Bool
omitField :: Typed v -> Bool
ToJSON)

makeLenses ''Typed