simple-expr-0.1.0.2: Minimalistic toolkit for simple mathematical expression.
Copyright(C) 2023 Alexey Tochin
LicenseBSD3 (see the file LICENSE)
MaintainerAlexey Tochin <Alexey.Tochin@gmail.com>
Safe HaskellNone
LanguageHaskell2010
Extensions
  • ScopedTypeVariables
  • ConstraintKinds
  • InstanceSigs
  • DeriveFunctor
  • TypeSynonymInstances
  • FlexibleContexts
  • FlexibleInstances
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • RankNTypes
  • ExplicitForAll

Debug.SimpleExpr.GraphUtils

Description

Tools for transforming simple expressions to graphs from graphite.

Synopsis

Conversion simple expressions to graphs

exprToGraph :: Expr d => d -> DGraph String () Source #

Transforms an expression to graph.

Examples of usage

Expand
>>> import Debug.SimpleExpr (variable)
>>> import NumHask ((+), (-))
>>> x = variable "x"
>>> y = variable "y"
>>> exprToGraph [x + y, x - y]
fromList [("x",[("x+y",()),("x-y",())]),("x+y",[]),("x-y",[]),("y",[("x+y",()),("x-y",())])]

Visualisation

plotExpr :: Expr d => d -> IO ThreadId Source #

Visualizes an expression.

Examples of usage

Expand
>>> import Debug.SimpleExpr (number, variable)
>>> import NumHask ((+), (-))
>>> import Data.Graph.VisualizeAlternative (plotDGraphPng)
>>> plotExpr (number 1 + variable "x")

>>> x = variable "x"
>>> y = variable "y"
>>> plotExpr [x + y, x - y]

plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath Source #

A copy of toDirectedDot method from Visualize but the parameter Sfdp is replaced by Dot.

Auxiliary functions

simpleExprToGraph :: SimpleExpr -> DGraph String () Source #

Transforms a simple expression to graph.

appendNodeToGraph :: String -> [String] -> DGraph String () -> DGraph String () Source #

Appends a node to a graph using string valued keys.

The first argumet is the new node name.

The second argument is the list of dependent nodes.