-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Procedures and Sequences -- -- A domain specific lanaguage for procedures. @package technique @version 0.2.5 module Technique.Quantity data Quantity Number :: Int64 -> Quantity Quantity :: Decimal -> Decimal -> Magnitude -> Symbol -> Quantity -- | A decimal number with a fixed point resolution. The resolution (number -- of decimal places) is arbitrary within the available range. This isn't -- really for numerical analysis. It is for carrying information. -- -- Implementation note -- -- Internally this is a floating point where the mantissa is 19 -- characters wide (the width of a 64-bit int in base 10). Thus the -- biggest number representable is 9223372036854775807 and the smallest -- is 0.0000000000000000001. We could change this to Integer and be -- arbitrary precision but meh. data Decimal Decimal :: Int64 -> Int8 -> Decimal type Magnitude = Int8 decimalToRope :: Decimal -> Rope isZeroDecimal :: Decimal -> Bool negateDecimal :: Decimal -> Decimal type Symbol = Rope data Unit Unit :: Rope -> Rope -> Rope -> Group -> Unit [unitName] :: Unit -> Rope [unitPlural] :: Unit -> Rope [unitSymbol] :: Unit -> Rope [unitGroup] :: Unit -> Group -- | Whether Système International metric prefixes can be used, or (as is -- the case of time units) quantities should not be aggregated to other -- scales. data Group Metric :: Group Time :: Group Normal :: Group Scientific :: Group Engineering :: Group data Prefix Prefix :: Rope -> Symbol -> Int -> Prefix [prefixName] :: Prefix -> Rope [prefixSymbol] :: Prefix -> Symbol [prefixScale] :: Prefix -> Int units :: Map Symbol Unit prefixes :: Map Symbol Prefix instance GHC.Classes.Ord Technique.Quantity.Decimal instance GHC.Classes.Eq Technique.Quantity.Decimal instance GHC.Classes.Ord Technique.Quantity.Quantity instance GHC.Classes.Eq Technique.Quantity.Quantity instance GHC.Show.Show Technique.Quantity.Quantity instance GHC.Classes.Eq Technique.Quantity.Group instance GHC.Show.Show Technique.Quantity.Group instance GHC.Classes.Eq Technique.Quantity.Prefix instance GHC.Show.Show Technique.Quantity.Prefix instance GHC.Classes.Eq Technique.Quantity.Unit instance GHC.Show.Show Technique.Quantity.Unit instance GHC.Show.Show Technique.Quantity.Decimal module Technique.Language data Technique Technique :: Int -> Rope -> Maybe Rope -> [Procedure] -> Technique [techniqueVersion] :: Technique -> Int [techniqueLicense] :: Technique -> Rope [techniqueCopyright] :: Technique -> Maybe Rope [techniqueBody] :: Technique -> [Procedure] emptyTechnique :: Technique data Identifier Identifier :: Rope -> Identifier unIdentifier :: Identifier -> Rope newtype Label Label :: Rope -> Label data Attribute Role :: Identifier -> Attribute Place :: Identifier -> Attribute Inherit :: Attribute data Markdown Markdown :: Rope -> Markdown data Type Type :: Rope -> Type unitType :: Type data Procedure Procedure :: Offset -> Identifier -> [Identifier] -> [Type] -> [Type] -> Maybe Markdown -> Maybe Markdown -> Block -> Procedure [procedureOffset] :: Procedure -> Offset [procedureName] :: Procedure -> Identifier [procedureParams] :: Procedure -> [Identifier] [procedureInput] :: Procedure -> [Type] [procedureOutput] :: Procedure -> [Type] [procedureTitle] :: Procedure -> Maybe Markdown [procedureDescription] :: Procedure -> Maybe Markdown [procedureBlock] :: Procedure -> Block emptyProcedure :: Procedure data Block Block :: [Statement] -> Block type Offset = Int class Located a locationOf :: Located a => a -> Offset data Statement Assignment :: Offset -> [Identifier] -> Expression -> Statement Execute :: Offset -> Expression -> Statement Comment :: Offset -> Rope -> Statement Declaration :: Offset -> Procedure -> Statement Blank :: Offset -> Statement Series :: Offset -> Statement data Expression Application :: Offset -> Identifier -> Expression -> Expression None :: Offset -> Expression Text :: Offset -> Rope -> Expression Amount :: Offset -> Quantity -> Expression Undefined :: Offset -> Expression Object :: Offset -> Tablet -> Expression Variable :: Offset -> [Identifier] -> Expression Operation :: Offset -> Operator -> Expression -> Expression -> Expression Grouping :: Offset -> Expression -> Expression Restriction :: Offset -> Attribute -> Block -> Expression data Tablet Tablet :: [Binding] -> Tablet data Binding Binding :: Label -> Expression -> Binding data Operator WaitEither :: Operator WaitBoth :: Operator Combine :: Operator instance Data.Hashable.Class.Hashable Technique.Language.Identifier instance GHC.Generics.Generic Technique.Language.Identifier instance GHC.Classes.Ord Technique.Language.Identifier instance GHC.Classes.Eq Technique.Language.Identifier instance GHC.Show.Show Technique.Language.Identifier instance GHC.Classes.Ord Technique.Language.Label instance GHC.Classes.Eq Technique.Language.Label instance GHC.Show.Show Technique.Language.Label instance GHC.Classes.Ord Technique.Language.Attribute instance GHC.Classes.Eq Technique.Language.Attribute instance GHC.Show.Show Technique.Language.Attribute instance GHC.Classes.Ord Technique.Language.Markdown instance GHC.Classes.Eq Technique.Language.Markdown instance GHC.Classes.Ord Technique.Language.Type instance GHC.Classes.Eq Technique.Language.Type instance GHC.Show.Show Technique.Language.Type instance GHC.Classes.Ord Technique.Language.Operator instance GHC.Classes.Eq Technique.Language.Operator instance GHC.Show.Show Technique.Language.Operator instance GHC.Classes.Ord Technique.Language.Procedure instance GHC.Classes.Eq Technique.Language.Procedure instance GHC.Show.Show Technique.Language.Procedure instance GHC.Classes.Eq Technique.Language.Statement instance GHC.Classes.Ord Technique.Language.Statement instance GHC.Show.Show Technique.Language.Statement instance GHC.Classes.Ord Technique.Language.Block instance GHC.Classes.Eq Technique.Language.Block instance GHC.Show.Show Technique.Language.Block instance GHC.Classes.Ord Technique.Language.Binding instance GHC.Classes.Eq Technique.Language.Binding instance GHC.Show.Show Technique.Language.Binding instance GHC.Classes.Eq Technique.Language.Tablet instance GHC.Classes.Ord Technique.Language.Tablet instance GHC.Show.Show Technique.Language.Tablet instance GHC.Classes.Eq Technique.Language.Expression instance GHC.Classes.Ord Technique.Language.Expression instance GHC.Show.Show Technique.Language.Expression instance GHC.Classes.Eq Technique.Language.Technique instance GHC.Show.Show Technique.Language.Technique instance Technique.Language.Located Technique.Language.Procedure instance Technique.Language.Located Technique.Language.Statement instance Technique.Language.Located Technique.Language.Expression instance GHC.Show.Show Technique.Language.Markdown instance Core.Data.Structures.Key Technique.Language.Identifier -- | Commentary -- -- We're optimizing for simplicity here. The language balances -- conventions from other languages with choices to not overcomplicate -- things. Not overloading operators, for example. Mostly we want to have -- "good error messages" which is tough and subjective anyway. Not having -- multiline anything, for example, might be a good choice, except that -- we also want to be whitepsace insensitive. module Technique.Parser pTechnique :: Parser Technique pMagicLine :: Parser Int pSpdxLine :: Parser (Rope, Maybe Rope) pIdentifier :: Parser Identifier pType :: Parser Type stringLiteral :: Parser Text numberLiteral :: Parser Int64 pQuantity :: Parser Quantity pAttribute :: Parser Attribute pExpression :: Parser Expression pStatement :: Parser Statement pBlock :: Parser Block pProcedureDeclaration :: Parser (Identifier, [Identifier], [Type], [Type]) pProcedureCode :: Parser Procedure -- | Builing blocks for the translation stage of the compiler. module Technique.Internal newtype Promise Promise :: Value -> Promise -- | The resolved value of eiter a literal or function applicaiton, either -- as that literal, the expression, or as the result of waiting on the -- variable it was assigned to. -- -- Need names? Science names newly discovered creatures in Latin. I don't -- speak Latin, but neither does anyone else so we can just make words -- up. Yeay! (The lengths some people will go to in order to avoid -- qualified imports is really impressive, isn't it?) data Value Unitus :: Value Literali :: Rope -> Value Quanticle :: Quantity -> Value Tabularum :: [(Rope, Value)] -> Value Parametriq :: [Value] -> Value -- | The internal representation of a Procedure, with ambiguities resolved. -- -- We landed on Subroutine as the name of translated user-defined -- Procedure. -- -- Procedures which are actually fundamental [in the context of the -- domain specific language] represented by builtin IO actions which we -- call Primatives. -- -- The first constructor, Unresolved, is for the first stage pass through -- the translate phase when we are still accumulating definitions, -- thereby allowing for the forward use of not-yet-defiend procedures -- that will be encountered in the same scope. data Function Unresolved :: Identifier -> Function Subroutine :: Procedure -> Step -> Function Primitive :: Procedure -> (Step -> IO Value) -> Function functionName :: Function -> Identifier newtype Name Name :: Rope -> Name -- | Names. Always needing names. These ones are from original work when we -- envisioned technique as a shallow embedding of a domain specific -- language implemented in Haskell. Comments describing constructors are -- taken from a suggestion by Oleg Kiselyov on page 23 of his course -- "Typed Tagless Final Interpreters" that the constructors of a simply -- typed lambda calculus in this style could be considered a "minimal -- intuitionistic logic" which is absolutely fabulous. data Step Known :: Offset -> Value -> Step Bench :: Offset -> [(Label, Step)] -> Step Depends :: Offset -> Name -> Step NoOp :: Step Tuple :: Offset -> [Step] -> Step Asynchronous :: Offset -> [Name] -> Step -> Step Invocation :: Offset -> Attribute -> Function -> Step -> Step Nested :: Offset -> DList Step -> Step instance GHC.Show.Show Technique.Internal.Value instance GHC.Classes.Eq Technique.Internal.Value instance GHC.Show.Show Technique.Internal.Name instance GHC.Classes.Eq Technique.Internal.Name instance GHC.Show.Show Technique.Internal.Step instance GHC.Classes.Eq Technique.Internal.Step instance GHC.Show.Show Technique.Internal.Function instance GHC.Classes.Eq Technique.Internal.Function instance Technique.Language.Located Technique.Internal.Step instance GHC.Base.Semigroup Technique.Internal.Step instance GHC.Base.Monoid Technique.Internal.Step -- | Given an instantiated Technique Procedure, evalutate it at runtime. module Technique.Evaluator -- | In order to execute a Procedure we need to supply a Context: an -- identifier for the event (collection of procedure calls) it is a part -- of, and the path history we took to get here. data Context Context :: UUID -> Rope -> Map Name Promise -> Context [contextEvent] :: Context -> UUID [contextPath] :: Context -> Rope [contextValues] :: Context -> Map Name Promise newtype Evaluate a Evaluate :: ReaderT Context IO a -> Evaluate a unEvaluate :: Evaluate a -> ReaderT Context IO a -- | The heart of the evaluation loop. Translate from the abstract syntax -- tree into a monadic sequence which results in a Result. evaluateStep :: Step -> Evaluate Value functionApplication :: Function -> Step -> Evaluate Value executeAction :: Function -> Step -> Evaluate Value blockUntilValue :: Name -> Evaluate Value -- | Take a step and lauch it asynchronously, binding its result to a name. -- Returns a promise of a value that can be in evaluated (block on) when -- needed. assignNames :: [Name] -> Step -> Evaluate Promise instance Control.Monad.Reader.Class.MonadReader Technique.Evaluator.Context Technique.Evaluator.Evaluate instance Control.Monad.IO.Class.MonadIO Technique.Evaluator.Evaluate instance GHC.Base.Monad Technique.Evaluator.Evaluate instance GHC.Base.Applicative Technique.Evaluator.Evaluate instance GHC.Base.Functor Technique.Evaluator.Evaluate -- | This is the beginnings of the standard library. module Technique.Builtins builtinProcedures :: Map Identifier Function builtinProcedureTask :: Function builtinProcedureRecord :: Function builtinProcedureWaitEither :: Function builtinProcedureWaitBoth :: Function builtinProcedureCombineValues :: Function module Technique.Formatter data TechniqueToken MagicToken :: TechniqueToken ProcedureToken :: TechniqueToken TypeToken :: TechniqueToken SymbolToken :: TechniqueToken OperatorToken :: TechniqueToken VariableToken :: TechniqueToken ApplicationToken :: TechniqueToken LabelToken :: TechniqueToken StringToken :: TechniqueToken QuantityToken :: TechniqueToken RoleToken :: TechniqueToken ErrorToken :: TechniqueToken FilenameToken :: TechniqueToken StepToken :: TechniqueToken colourizeTechnique :: TechniqueToken -> AnsiColour -- | Punctuate a list with commas annotated with Symbol highlighting. commaCat :: (Render a, Token a ~ TechniqueToken) => [a] -> Doc (Token a) numberToSuperscript :: Int8 -> Doc ann toSuperscript :: Char -> Char instance Core.Text.Utilities.Render Technique.Language.Procedure instance Core.Text.Utilities.Render Technique.Language.Type instance Core.Text.Utilities.Render Technique.Language.Markdown instance Core.Text.Utilities.Render Technique.Language.Block instance Core.Text.Utilities.Render Technique.Language.Statement instance Core.Text.Utilities.Render Technique.Language.Attribute instance Core.Text.Utilities.Render Technique.Language.Expression instance Core.Text.Utilities.Render Technique.Language.Identifier instance Core.Text.Utilities.Render Technique.Quantity.Decimal instance Core.Text.Utilities.Render Technique.Quantity.Quantity instance Core.Text.Utilities.Render Technique.Language.Tablet instance Core.Text.Utilities.Render Technique.Language.Label instance Core.Text.Utilities.Render Technique.Language.Binding instance Core.Text.Utilities.Render Technique.Language.Operator instance Core.Text.Utilities.Render Technique.Language.Technique instance Prettyprinter.Internal.Pretty Technique.Language.Procedure instance Prettyprinter.Internal.Pretty Technique.Language.Identifier instance Prettyprinter.Internal.Pretty Technique.Quantity.Quantity instance Prettyprinter.Internal.Pretty Technique.Language.Label -- | Error messages from compiling. module Technique.Failure data Status Ok :: Status Failed :: CompilationError -> Status Reload :: Status data Source Source :: Rope -> FilePath -> !Offset -> Source [sourceContents] :: Source -> Rope [sourceFilename] :: Source -> FilePath [sourceOffset] :: Source -> !Offset emptySource :: Source data FailureReason InvalidSetup :: FailureReason ParsingFailed :: [ErrorItem Char] -> [ErrorItem Char] -> FailureReason VariableAlreadyInUse :: Identifier -> FailureReason ProcedureAlreadyDeclared :: Identifier -> FailureReason CallToUnknownProcedure :: Identifier -> FailureReason UseOfUnknownIdentifier :: Identifier -> FailureReason EncounteredUndefined :: FailureReason data CompilationError CompilationError :: Source -> FailureReason -> CompilationError exitCodeFor :: CompilationError -> Int fancyPunctuate :: [Doc ann] -> [Doc ann] -- | ErrorItem is a bit overbearing, but we handle its four cases by -- saying single quotes around characters, double quotes around strings, -- no quotes around labels (descriptive text) and hard code the -- end of input and newline cases. formatErrorItem :: TechniqueToken -> ErrorItem Char -> Doc TechniqueToken numberOfCarots :: FailureReason -> Int -- | When we get a failure in the parsing stage **megaparsec** returns a -- ParseErrorBundle. Extract the first error message therein (later -- handle more? Yeah nah), and convert it into something we can use. extractErrorBundle :: Source -> ParseErrorBundle Text Void -> CompilationError extractParseError :: ParseError Text Void -> (Int, [ErrorItem Char], [ErrorItem Char]) instance GHC.Show.Show Technique.Failure.Source instance GHC.Classes.Ord Technique.Failure.Source instance GHC.Classes.Eq Technique.Failure.Source instance GHC.Classes.Eq Technique.Failure.FailureReason instance GHC.Show.Show Technique.Failure.FailureReason instance GHC.Show.Show Technique.Failure.CompilationError instance Core.Text.Utilities.Render Technique.Failure.Status instance GHC.Exception.Type.Exception Technique.Failure.CompilationError instance Core.Text.Utilities.Render Technique.Failure.CompilationError instance GHC.Enum.Enum Technique.Failure.FailureReason instance Core.Text.Utilities.Render Technique.Failure.FailureReason instance Technique.Language.Located Technique.Failure.Source instance Core.Text.Utilities.Render Technique.Failure.Source module Technique.Diagnostics instance Core.Text.Utilities.Render Technique.Internal.Function instance Core.Text.Utilities.Render Technique.Internal.Step instance Core.Text.Utilities.Render Technique.Internal.Name instance Core.Text.Utilities.Render Technique.Internal.Value -- | Given a Technique Procedure (concrete syntax tree), translate it into -- an internalized representation (abstract syntax tree) that can be -- subsequently executed (that is, interpreted; evaluated). module Technique.Translate -- | Environment in the type-theory sense of the word: the map(s) between -- names and their bindings. data Environment Environment :: Map Identifier Name -> Map Identifier Function -> Attribute -> Source -> Step -> Environment [environmentVariables] :: Environment -> Map Identifier Name [environmentFunctions] :: Environment -> Map Identifier Function [environmentRole] :: Environment -> Attribute [environmentSource] :: Environment -> Source [environmentAccumulated] :: Environment -> Step emptyEnvironment :: Environment newtype Translate a Translate :: StateT Environment (Except CompilationError) a -> Translate a -- | Take a translator action and an environment and spin it up into a Step -- or nest of Steps (Subroutine) suitable for interpretation. In -- other words, translate between the concrete syntax types and the -- abstract syntax we can feed to an evaluator. runTranslate :: Environment -> Translate a -> Either CompilationError (a, Environment) translateTechnique :: Technique -> Translate [Function] translateProcedure :: Procedure -> Translate Function -- | Blocks are scoping mechanisms, so accumulated environment is discarded -- once we finish resolving names within it. translateBlock :: Block -> Translate Step translateStatement :: Statement -> Translate () -- | Note that this does NOT add the steps to the Environment. translateExpression :: Expression -> Translate Step -- | A given procedure call can either be to a user declared in-scope -- procedure or to a primative builtin. We have Invocation as the Step -- constructors for these cases. registerProcedure :: Offset -> Function -> Translate () failBecause :: Offset -> FailureReason -> Translate a lookupVariable :: Offset -> Identifier -> Translate Name -- | Identifiers are valid names but Names are unique, so that we can put -- them into the environment map. This is where we check for reuse of an -- already declared name (TODO) and given the local use of the identifier -- a scope-local (or globally?) unique name. insertVariable :: Offset -> Identifier -> Translate Name -- | Accumulate a Step. appendStep :: Step -> Translate () -- | This begins a new (more refined) scope and does *not* add its -- declarations or variables to the current environment. applyRestriction :: Attribute -> Block -> Translate Step -- | The second stage of translation phase: iterate through the Steps and -- where a function call is made, look up to see if we actually know what -- it is. resolveFunctions :: Step -> Translate Step lookupFunction :: Offset -> Function -> Translate Function -- | Update the environment's idea of where in the source we are, so that -- if we need to generate an error message we can offer one with position -- information. setLocationFrom :: Located a => a -> Translate () instance GHC.Show.Show Technique.Translate.Environment instance GHC.Classes.Eq Technique.Translate.Environment instance Control.Monad.Error.Class.MonadError Technique.Failure.CompilationError Technique.Translate.Translate instance Control.Monad.State.Class.MonadState Technique.Translate.Environment Technique.Translate.Translate instance GHC.Base.Monad Technique.Translate.Translate instance GHC.Base.Applicative Technique.Translate.Translate instance GHC.Base.Functor Technique.Translate.Translate