{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}

-- | Specifics of the TI-85 variables themselves
-- (i.e. not their representation in the file).
module Data.TI85.Var (
    -- * Types
    Variable(..),
    TINumber(..),
    -- ** Program
    Program(..),
    Token(..),
    -- ** Window Settings
    FuncSettings(..),
    PolarSettings(..),
    ParamSettings(..),
    SavedWinSettings(..),
    -- *** Differential Equations
    DiffEqSettings(..),
    DiffEqAxis(..),
    AxisInd(..),
    -- ** Graph Database
    ModeSettings(..),
    GraphMode(..),
    FuncEqn(..),
    ParamEqn(..),
    DiffEqEqn(..),
    GDBLibEntry(..),
    GDBEqn(..),
    GDBSettings(..),
    GDB(..),
    HasGDB,

    -- * Text Conversion
    showVariable,
    -- ** Variable-specific
    showNumber,
    showProgram,
    showFuncSettings,
    showPolarSettings,
    showParamSettings,
    showDiffEqSettings,
    showWinSettings,
    showGDB,
    showGDBMode,

    -- * IO
    printVariable
    ) where

import Prelude hiding (concat, putStrLn)
import Data.Text (Text, concat, pack, intercalate, unpack)
import Data.Text.IO (putStrLn)
import Data.TI85.Token (TokenDef)
import Data.TI85.Var.Pic

-- * Types

-- | An instance of a token from the `TokenDef`
-- table. This will include actual text that goes
-- along with a token, when it is not a fixed-text
-- token.
data Token = Token TokenDef Text deriving Int -> Token -> ShowS
[Token] -> ShowS
Token -> String
(Int -> Token -> ShowS)
-> (Token -> String) -> ([Token] -> ShowS) -> Show Token
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Token -> ShowS
showsPrec :: Int -> Token -> ShowS
$cshow :: Token -> String
show :: Token -> String
$cshowList :: [Token] -> ShowS
showList :: [Token] -> ShowS
Show

-- | A program is either stored as plaintext
-- (in the TI-86 codepage; see `Data.TI85.Encoding.tiDecode`)
-- or a list of tokens. The two are represented here to
-- maintain that information.
data Program = PlainText Text
    | Tokenized [Token]
    deriving Int -> Program -> ShowS
[Program] -> ShowS
Program -> String
(Int -> Program -> ShowS)
-> (Program -> String) -> ([Program] -> ShowS) -> Show Program
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Program -> ShowS
showsPrec :: Int -> Program -> ShowS
$cshow :: Program -> String
show :: Program -> String
$cshowList :: [Program] -> ShowS
showList :: [Program] -> ShowS
Show

-- | Numerical variables are either Real or Complex.
data TINumber = TIReal Double | TIComplex Double Double deriving Int -> TINumber -> ShowS
[TINumber] -> ShowS
TINumber -> String
(Int -> TINumber -> ShowS)
-> (TINumber -> String) -> ([TINumber] -> ShowS) -> Show TINumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TINumber -> ShowS
showsPrec :: Int -> TINumber -> ShowS
$cshow :: TINumber -> String
show :: TINumber -> String
$cshowList :: [TINumber] -> ShowS
showList :: [TINumber] -> ShowS
Show

-- ** Window Settings

-- | Function window settings
data FuncSettings = FuncSettings {
    FuncSettings -> TINumber
fXMin :: TINumber,
    FuncSettings -> TINumber
fXMax :: TINumber,
    FuncSettings -> TINumber
fXScl :: TINumber,
    FuncSettings -> TINumber
fYMin :: TINumber,
    FuncSettings -> TINumber
fYMax :: TINumber,
    FuncSettings -> TINumber
fYScl :: TINumber
    }
    deriving Int -> FuncSettings -> ShowS
[FuncSettings] -> ShowS
FuncSettings -> String
(Int -> FuncSettings -> ShowS)
-> (FuncSettings -> String)
-> ([FuncSettings] -> ShowS)
-> Show FuncSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FuncSettings -> ShowS
showsPrec :: Int -> FuncSettings -> ShowS
$cshow :: FuncSettings -> String
show :: FuncSettings -> String
$cshowList :: [FuncSettings] -> ShowS
showList :: [FuncSettings] -> ShowS
Show

-- | Polar window settings
data PolarSettings = PolarSettings {
    PolarSettings -> TINumber
polThetaMin :: TINumber,
    PolarSettings -> TINumber
polThetaMax :: TINumber,
    PolarSettings -> TINumber
polThetaStep :: TINumber,
    PolarSettings -> TINumber
polXMin :: TINumber,
    PolarSettings -> TINumber
polXMax :: TINumber,
    PolarSettings -> TINumber
polXScl :: TINumber,
    PolarSettings -> TINumber
polYMin :: TINumber,
    PolarSettings -> TINumber
polYMax :: TINumber,
    PolarSettings -> TINumber
polYScl :: TINumber
    }
    deriving Int -> PolarSettings -> ShowS
[PolarSettings] -> ShowS
PolarSettings -> String
(Int -> PolarSettings -> ShowS)
-> (PolarSettings -> String)
-> ([PolarSettings] -> ShowS)
-> Show PolarSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PolarSettings -> ShowS
showsPrec :: Int -> PolarSettings -> ShowS
$cshow :: PolarSettings -> String
show :: PolarSettings -> String
$cshowList :: [PolarSettings] -> ShowS
showList :: [PolarSettings] -> ShowS
Show

-- | Parametric window settings
data ParamSettings = ParamSettings {
    ParamSettings -> TINumber
parTMin :: TINumber,
    ParamSettings -> TINumber
parTMax :: TINumber,
    ParamSettings -> TINumber
parTStep :: TINumber,
    ParamSettings -> TINumber
parXMin :: TINumber,
    ParamSettings -> TINumber
parXMax :: TINumber,
    ParamSettings -> TINumber
parXScl :: TINumber,
    ParamSettings -> TINumber
parYMin :: TINumber,
    ParamSettings -> TINumber
parYMax :: TINumber,
    ParamSettings -> TINumber
parYScl :: TINumber
    }
    deriving Int -> ParamSettings -> ShowS
[ParamSettings] -> ShowS
ParamSettings -> String
(Int -> ParamSettings -> ShowS)
-> (ParamSettings -> String)
-> ([ParamSettings] -> ShowS)
-> Show ParamSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParamSettings -> ShowS
showsPrec :: Int -> ParamSettings -> ShowS
$cshow :: ParamSettings -> String
show :: ParamSettings -> String
$cshowList :: [ParamSettings] -> ShowS
showList :: [ParamSettings] -> ShowS
Show

-- | Differential equation axes can come
-- with an index (e.g. Q1-Q9).
data AxisInd = Axis0
    | Axis1
    | Axis2
    | Axis3
    | Axis4
    | Axis5
    | Axis6
    | Axis7
    | Axis8
    | Axis9
    deriving (Int -> AxisInd -> ShowS
[AxisInd] -> ShowS
AxisInd -> String
(Int -> AxisInd -> ShowS)
-> (AxisInd -> String) -> ([AxisInd] -> ShowS) -> Show AxisInd
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AxisInd -> ShowS
showsPrec :: Int -> AxisInd -> ShowS
$cshow :: AxisInd -> String
show :: AxisInd -> String
$cshowList :: [AxisInd] -> ShowS
showList :: [AxisInd] -> ShowS
Show,AxisInd -> AxisInd -> Bool
(AxisInd -> AxisInd -> Bool)
-> (AxisInd -> AxisInd -> Bool) -> Eq AxisInd
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AxisInd -> AxisInd -> Bool
== :: AxisInd -> AxisInd -> Bool
$c/= :: AxisInd -> AxisInd -> Bool
/= :: AxisInd -> AxisInd -> Bool
Eq,Int -> AxisInd
AxisInd -> Int
AxisInd -> [AxisInd]
AxisInd -> AxisInd
AxisInd -> AxisInd -> [AxisInd]
AxisInd -> AxisInd -> AxisInd -> [AxisInd]
(AxisInd -> AxisInd)
-> (AxisInd -> AxisInd)
-> (Int -> AxisInd)
-> (AxisInd -> Int)
-> (AxisInd -> [AxisInd])
-> (AxisInd -> AxisInd -> [AxisInd])
-> (AxisInd -> AxisInd -> [AxisInd])
-> (AxisInd -> AxisInd -> AxisInd -> [AxisInd])
-> Enum AxisInd
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: AxisInd -> AxisInd
succ :: AxisInd -> AxisInd
$cpred :: AxisInd -> AxisInd
pred :: AxisInd -> AxisInd
$ctoEnum :: Int -> AxisInd
toEnum :: Int -> AxisInd
$cfromEnum :: AxisInd -> Int
fromEnum :: AxisInd -> Int
$cenumFrom :: AxisInd -> [AxisInd]
enumFrom :: AxisInd -> [AxisInd]
$cenumFromThen :: AxisInd -> AxisInd -> [AxisInd]
enumFromThen :: AxisInd -> AxisInd -> [AxisInd]
$cenumFromTo :: AxisInd -> AxisInd -> [AxisInd]
enumFromTo :: AxisInd -> AxisInd -> [AxisInd]
$cenumFromThenTo :: AxisInd -> AxisInd -> AxisInd -> [AxisInd]
enumFromThenTo :: AxisInd -> AxisInd -> AxisInd -> [AxisInd]
Enum)

-- | Differential equation axis type
data DiffEqAxis = AxisT
    | AxisQ AxisInd
    | AxisQ' AxisInd
    deriving Int -> DiffEqAxis -> ShowS
[DiffEqAxis] -> ShowS
DiffEqAxis -> String
(Int -> DiffEqAxis -> ShowS)
-> (DiffEqAxis -> String)
-> ([DiffEqAxis] -> ShowS)
-> Show DiffEqAxis
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DiffEqAxis -> ShowS
showsPrec :: Int -> DiffEqAxis -> ShowS
$cshow :: DiffEqAxis -> String
show :: DiffEqAxis -> String
$cshowList :: [DiffEqAxis] -> ShowS
showList :: [DiffEqAxis] -> ShowS
Show

-- | Differential equation window settings
data DiffEqSettings = DiffEqSettings {
    DiffEqSettings -> TINumber
diffTol :: TINumber,
    DiffEqSettings -> TINumber
diffTPlot :: TINumber,
    DiffEqSettings -> TINumber
diffTMin :: TINumber,
    DiffEqSettings -> TINumber
diffTMax :: TINumber,
    DiffEqSettings -> TINumber
diffTStep :: TINumber,
    DiffEqSettings -> TINumber
diffXMin :: TINumber,
    DiffEqSettings -> TINumber
diffXMax :: TINumber,
    DiffEqSettings -> TINumber
diffXScl :: TINumber,
    DiffEqSettings -> TINumber
diffYMin :: TINumber,
    DiffEqSettings -> TINumber
diffYMax :: TINumber,
    DiffEqSettings -> TINumber
diffYScl :: TINumber,
    DiffEqSettings -> DiffEqAxis
diffXAxis :: DiffEqAxis,
    DiffEqSettings -> DiffEqAxis
diffYAxis :: DiffEqAxis
    }
    deriving Int -> DiffEqSettings -> ShowS
[DiffEqSettings] -> ShowS
DiffEqSettings -> String
(Int -> DiffEqSettings -> ShowS)
-> (DiffEqSettings -> String)
-> ([DiffEqSettings] -> ShowS)
-> Show DiffEqSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DiffEqSettings -> ShowS
showsPrec :: Int -> DiffEqSettings -> ShowS
$cshow :: DiffEqSettings -> String
show :: DiffEqSettings -> String
$cshowList :: [DiffEqSettings] -> ShowS
showList :: [DiffEqSettings] -> ShowS
Show

-- | Saved window settings, used for ZRCL.
data SavedWinSettings = SavedWinSettings {
    SavedWinSettings -> TINumber
zThetaMin :: TINumber,
    SavedWinSettings -> TINumber
zThetaMax :: TINumber,
    SavedWinSettings -> TINumber
zThetaStep :: TINumber,
    SavedWinSettings -> TINumber
ztPlot :: TINumber,
    SavedWinSettings -> TINumber
ztMin :: TINumber,
    SavedWinSettings -> TINumber
ztMax :: TINumber,
    SavedWinSettings -> TINumber
ztStep :: TINumber,
    SavedWinSettings -> TINumber
zxMin :: TINumber,
    SavedWinSettings -> TINumber
zxMax :: TINumber,
    SavedWinSettings -> TINumber
zxScl :: TINumber,
    SavedWinSettings -> TINumber
zyMin :: TINumber,
    SavedWinSettings -> TINumber
zyMax :: TINumber,
    SavedWinSettings -> TINumber
zyScl :: TINumber
    }
    deriving Int -> SavedWinSettings -> ShowS
[SavedWinSettings] -> ShowS
SavedWinSettings -> String
(Int -> SavedWinSettings -> ShowS)
-> (SavedWinSettings -> String)
-> ([SavedWinSettings] -> ShowS)
-> Show SavedWinSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SavedWinSettings -> ShowS
showsPrec :: Int -> SavedWinSettings -> ShowS
$cshow :: SavedWinSettings -> String
show :: SavedWinSettings -> String
$cshowList :: [SavedWinSettings] -> ShowS
showList :: [SavedWinSettings] -> ShowS
Show

data ModeSettings = ModeSettings {
    ModeSettings -> Bool
modeDrawDot :: Bool,
    ModeSettings -> Bool
modeSimulG :: Bool,
    ModeSettings -> Bool
modeGridOn :: Bool,
    ModeSettings -> Bool
modePolarGC :: Bool,
    ModeSettings -> Bool
modeCoordOff :: Bool,
    ModeSettings -> Bool
modeAxesOff :: Bool,
    ModeSettings -> Bool
modeLabelOn :: Bool
    }
    deriving Int -> ModeSettings -> ShowS
[ModeSettings] -> ShowS
ModeSettings -> String
(Int -> ModeSettings -> ShowS)
-> (ModeSettings -> String)
-> ([ModeSettings] -> ShowS)
-> Show ModeSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModeSettings -> ShowS
showsPrec :: Int -> ModeSettings -> ShowS
$cshow :: ModeSettings -> String
show :: ModeSettings -> String
$cshowList :: [ModeSettings] -> ShowS
showList :: [ModeSettings] -> ShowS
Show

-- | There are four graph modes, each with
-- its own set of window ranges and equation
-- types.
data GraphMode = Func | Polar | Param | DiffEq

-- | Plain functions and Polar functions both use
-- a single equation.
type FuncEqn = Text

-- | Parametric functions use a pair of equations
data ParamEqn = ParamEqn {
    ParamEqn -> Text
xEqn :: Text,
    ParamEqn -> Text
yEqn :: Text
    } deriving Int -> ParamEqn -> ShowS
[ParamEqn] -> ShowS
ParamEqn -> String
(Int -> ParamEqn -> ShowS)
-> (ParamEqn -> String) -> ([ParamEqn] -> ShowS) -> Show ParamEqn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParamEqn -> ShowS
showsPrec :: Int -> ParamEqn -> ShowS
$cshow :: ParamEqn -> String
show :: ParamEqn -> String
$cshowList :: [ParamEqn] -> ShowS
showList :: [ParamEqn] -> ShowS
Show

-- | Differential equations have a single equation
-- paired with an initial condition.
data DiffEqEqn = DiffEqEqn {
    DiffEqEqn -> Text
diffEqn :: Text,
    DiffEqEqn -> Double
diffIC :: Double
    } deriving Int -> DiffEqEqn -> ShowS
[DiffEqEqn] -> ShowS
DiffEqEqn -> String
(Int -> DiffEqEqn -> ShowS)
-> (DiffEqEqn -> String)
-> ([DiffEqEqn] -> ShowS)
-> Show DiffEqEqn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DiffEqEqn -> ShowS
showsPrec :: Int -> DiffEqEqn -> ShowS
$cshow :: DiffEqEqn -> String
show :: DiffEqEqn -> String
$cshowList :: [DiffEqEqn] -> ShowS
showList :: [DiffEqEqn] -> ShowS
Show

class HasGDB (a :: GraphMode) where
    type GDBEqn a :: *
    type GDBSettings a :: *

    showGDBSettings :: GDB a -> Text
    showGDBHeader :: GDB a -> Text

    showGDBLib :: GDB a -> Text
    showGDBLib GDB a
gdb = Text -> [Text] -> Text
intercalate Text
"\n" ((GDBLibEntry a -> Text) -> [GDBLibEntry a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map GDBLibEntry a -> Text
forall (a :: GraphMode). HasGDB a => GDBLibEntry a -> Text
showGDBEntry (GDB a -> [GDBLibEntry a]
forall (a :: GraphMode). GDB a -> [GDBLibEntry a]
gdbLib GDB a
gdb))

    showGDBEntry :: GDBLibEntry a -> Text

instance HasGDB Func where
    type GDBEqn Func = FuncEqn
    type GDBSettings Func = FuncSettings

    showGDBSettings :: GDB 'Func -> Text
showGDBSettings GDB 'Func
gdb = FuncSettings -> Text
showFuncSettings (GDB 'Func -> GDBSettings 'Func
forall (a :: GraphMode). GDB a -> GDBSettings a
gdbSettings GDB 'Func
gdb)
    showGDBHeader :: GDB 'Func -> Text
showGDBHeader GDB 'Func
_ = Text
"ID\tSelected\tEquation\n"
    showGDBEntry :: GDBLibEntry 'Func -> Text
showGDBEntry (GDBLibEntry Int
entryId Bool
selected GDBEqn 'Func
eqn) =
        Int -> Text
forall a. Show a => a -> Text
showText Int
entryId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText Bool
selected Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
GDBEqn 'Func
eqn

instance HasGDB Polar where
    type GDBEqn Polar = FuncEqn
    type GDBSettings Polar = PolarSettings
    showGDBSettings :: GDB 'Polar -> Text
showGDBSettings GDB 'Polar
gdb = PolarSettings -> Text
showPolarSettings (GDB 'Polar -> GDBSettings 'Polar
forall (a :: GraphMode). GDB a -> GDBSettings a
gdbSettings GDB 'Polar
gdb)
    showGDBHeader :: GDB 'Polar -> Text
showGDBHeader GDB 'Polar
_ = Text
"ID\tSelected\tEquation\n"
    showGDBEntry :: GDBLibEntry 'Polar -> Text
showGDBEntry (GDBLibEntry Int
entryId Bool
selected GDBEqn 'Polar
eqn) =
        Int -> Text
forall a. Show a => a -> Text
showText Int
entryId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText Bool
selected Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
GDBEqn 'Polar
eqn

instance HasGDB Param where
    type GDBEqn Param = ParamEqn
    type GDBSettings Param = ParamSettings
    showGDBSettings :: GDB 'Param -> Text
showGDBSettings GDB 'Param
gdb = ParamSettings -> Text
showParamSettings (GDB 'Param -> GDBSettings 'Param
forall (a :: GraphMode). GDB a -> GDBSettings a
gdbSettings GDB 'Param
gdb)
    showGDBHeader :: GDB 'Param -> Text
showGDBHeader GDB 'Param
_ = Text
"ID\tSelected\tx-Equation\ty-Equation\n"
    showGDBEntry :: GDBLibEntry 'Param -> Text
showGDBEntry (GDBLibEntry Int
entryId Bool
selected GDBEqn 'Param
eqn) =
        Int -> Text
forall a. Show a => a -> Text
showText Int
entryId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText Bool
selected Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ParamEqn -> Text
xEqn GDBEqn 'Param
ParamEqn
eqn Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ParamEqn -> Text
yEqn GDBEqn 'Param
ParamEqn
eqn

instance HasGDB DiffEq where
    type GDBEqn DiffEq = DiffEqEqn
    type GDBSettings DiffEq = DiffEqSettings
    showGDBSettings :: GDB 'DiffEq -> Text
showGDBSettings GDB 'DiffEq
gdb = DiffEqSettings -> Text
showDiffEqSettings (GDB 'DiffEq -> GDBSettings 'DiffEq
forall (a :: GraphMode). GDB a -> GDBSettings a
gdbSettings GDB 'DiffEq
gdb)
    showGDBHeader :: GDB 'DiffEq -> Text
showGDBHeader GDB 'DiffEq
_ = Text
"ID\tSelected\tEquation\tInitial Condition\n"
    showGDBEntry :: GDBLibEntry 'DiffEq -> Text
showGDBEntry (GDBLibEntry Int
entryId Bool
selected GDBEqn 'DiffEq
eqn) =
        Int -> Text
forall a. Show a => a -> Text
showText Int
entryId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText Bool
selected Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DiffEqEqn -> Text
diffEqn GDBEqn 'DiffEq
DiffEqEqn
eqn Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\t"
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Double -> Text
forall a. Show a => a -> Text
showText (DiffEqEqn -> Double
diffIC GDBEqn 'DiffEq
DiffEqEqn
eqn)


-- | A graph database entry, containing a
-- function ID, whether or not it is currently
-- selected, and the equations that define the
-- function.
data GDBLibEntry (a :: GraphMode) = GDBLibEntry {
        forall (a :: GraphMode). GDBLibEntry a -> Int
libId :: Int,
        forall (a :: GraphMode). GDBLibEntry a -> Bool
libSelected :: Bool,
        forall (a :: GraphMode). GDBLibEntry a -> GDBEqn a
libEqn :: GDBEqn a
        }

-- | A graph database contains mode settings, window
-- settings, and a library of functions. The latter two
-- depend on the graphcs mode.
data GDB (a :: GraphMode) = GDB {
        forall (a :: GraphMode). GDB a -> ModeSettings
gdbMode :: ModeSettings,
        forall (a :: GraphMode). GDB a -> GDBSettings a
gdbSettings :: GDBSettings a,
        forall (a :: GraphMode). GDB a -> [GDBLibEntry a]
gdbLib :: [GDBLibEntry a]
        }

instance HasGDB a => Show (GDB (a :: GraphMode)) where
    show :: GDB a -> String
show GDB a
gdb = Text -> String
unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ GDB a -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB a
gdb


-- | Variables have a type and type-specific data.
-- See also `Data.TI85.File.Variable.VarType`.
data Variable =
    TIScalar TINumber
    | TIVector [TINumber]
    | TIList [TINumber]
    | TIMatrix [[TINumber]]
    | TIConstant TINumber
    | TIEquation Text
    | TIString Text
    | TIProgram Program
    | TIPicture TIBitmap
    | TIFuncSettings FuncSettings
    | TIPolarSettings PolarSettings
    | TIParamSettings ParamSettings
    | TIDiffEqSettings DiffEqSettings
    | TIZRCL SavedWinSettings
    | TIFuncGDB (GDB Func)
    | TIPolarGDB (GDB Polar)
    | TIParamGDB (GDB Param)
    | TIDiffEqGDB (GDB DiffEq)
    deriving Int -> Variable -> ShowS
[Variable] -> ShowS
Variable -> String
(Int -> Variable -> ShowS)
-> (Variable -> String) -> ([Variable] -> ShowS) -> Show Variable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Variable -> ShowS
showsPrec :: Int -> Variable -> ShowS
$cshow :: Variable -> String
show :: Variable -> String
$cshowList :: [Variable] -> ShowS
showList :: [Variable] -> ShowS
Show

-- * Text Conversion

-- | Utility for converting a showable
-- to Text.
showText :: Show a => a -> Text
showText :: forall a. Show a => a -> Text
showText = String -> Text
pack(String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.a -> String
forall a. Show a => a -> String
show

-- | Convert a TINumber to Text.
showNumber :: TINumber -> Text
showNumber :: TINumber -> Text
showNumber (TIReal Double
x) = Double -> Text
forall a. Show a => a -> Text
showText Double
x
showNumber (TIComplex Double
x Double
y) = Double -> Text
forall a. Show a => a -> Text
showText Double
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"+" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Double -> Text
forall a. Show a => a -> Text
showText Double
y Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"i"

-- | Convert a Program to Text.
showProgram :: Program -> Text
showProgram :: Program -> Text
showProgram (PlainText Text
progText) = Text
progText
showProgram (Tokenized [Token]
tokens) =
    (Token -> Text) -> [Token] -> Text
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Token TokenDef
_ Text
t) -> Text
t) [Token]
tokens

-- ** Window Settings

-- | Function window settings.
showFuncSettings :: FuncSettings -> Text
showFuncSettings :: FuncSettings -> Text
showFuncSettings FuncSettings
settings =
    Text
"\nxMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fXMin FuncSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fXMax FuncSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fXScl FuncSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fYMin FuncSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fYMax FuncSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (FuncSettings -> TINumber
fYScl FuncSettings
settings)

-- | Polar window settings.
showPolarSettings :: PolarSettings -> Text
showPolarSettings :: PolarSettings -> Text
showPolarSettings PolarSettings
settings =
    Text
"\nθMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polThetaMin PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nθMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polThetaMax PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nθStep: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polThetaStep PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polXMin PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polXMax PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polXScl PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polYMin PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polYMax PolarSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (PolarSettings -> TINumber
polYScl PolarSettings
settings)

-- | Parametric window settings.
showParamSettings :: ParamSettings -> Text
showParamSettings :: ParamSettings -> Text
showParamSettings ParamSettings
settings =
    Text
"\ntMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parTMin ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parTMax ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntStep: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parTStep ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parXMin ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parXMax ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parXScl ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parYMin ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parYMax ParamSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (ParamSettings -> TINumber
parYScl ParamSettings
settings)

-- | DiffEq window settings.
showDiffEqSettings :: DiffEqSettings -> Text
showDiffEqSettings :: DiffEqSettings -> Text
showDiffEqSettings DiffEqSettings
settings =
    Text
"\ndiffTol: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffTol DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntPlot: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffTPlot DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffTMin DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffTMax DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\ntStep: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffTStep DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffXMin DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffXMax DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffXScl DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffYMin DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffYMax DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (DiffEqSettings -> TINumber
diffYScl DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nxAxis: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DiffEqAxis -> Text
showAxis (DiffEqSettings -> DiffEqAxis
diffXAxis DiffEqSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nyAxis: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DiffEqAxis -> Text
showAxis (DiffEqSettings -> DiffEqAxis
diffYAxis DiffEqSettings
settings)
  where
    showAxis :: DiffEqAxis -> Text
    showAxis :: DiffEqAxis -> Text
showAxis DiffEqAxis
AxisT = Text
"t"
    showAxis (AxisQ AxisInd
ai) =
        let ind :: Int
ind = AxisInd -> Int
forall a. Enum a => a -> Int
fromEnum AxisInd
ai
        in if Int
ind Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
            then Text
"Q"
            else Text
"Q" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showText Int
ind
    showAxis (AxisQ' AxisInd
ai) =
        let ind :: Int
ind = AxisInd -> Int
forall a. Enum a => a -> Int
fromEnum AxisInd
ai
        in if Int
ind Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
            then Text
"Q'"
            else Text
"Q'" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showText Int
ind

-- | Saved window settings.
showWinSettings :: SavedWinSettings -> Text
showWinSettings :: SavedWinSettings -> Text
showWinSettings SavedWinSettings
settings =
    Text
"\nzθMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zThetaMin SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzθMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zThetaMax SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzθStep: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zThetaStep SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nztPlot: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
ztPlot SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nztMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
ztMin SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nztMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
ztMax SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nztStep: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
ztStep SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzxMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zxMin SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzxMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zxMax SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzxScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zxScl SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzyMin: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zyMin SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzyMax: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zyMax SavedWinSettings
settings)
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\nzyScl: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TINumber -> Text
showNumber (SavedWinSettings -> TINumber
zyScl SavedWinSettings
settings)

showGDBMode :: ModeSettings -> Text
showGDBMode :: ModeSettings -> Text
showGDBMode ModeSettings
mode =
    Text
"Dot/Line: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if ModeSettings -> Bool
modeDrawDot ModeSettings
mode then Text
"Dot" else Text
"Line" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Simul/Seq: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if ModeSettings -> Bool
modeSimulG ModeSettings
mode then Text
"Simul" else Text
"Seq" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Grid: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText (ModeSettings -> Bool
modeGridOn ModeSettings
mode) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Polar: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText (ModeSettings -> Bool
modePolarGC ModeSettings
mode) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Coord: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ModeSettings -> Bool
modeCoordOff ModeSettings
mode) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Axes: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ModeSettings -> Bool
modeAxesOff ModeSettings
mode) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Label: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Bool -> Text
forall a. Show a => a -> Text
showText (ModeSettings -> Bool
modeLabelOn ModeSettings
mode) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"

showGDB :: HasGDB (a :: GraphMode) => GDB (a :: GraphMode) -> Text
showGDB :: forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB a
gdb =
    Text
"Mode Settings:\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ModeSettings -> Text
showGDBMode (GDB a -> ModeSettings
forall (a :: GraphMode). GDB a -> ModeSettings
gdbMode GDB a
gdb) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Window Settings:"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> GDB a -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDBSettings GDB a
gdb Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"Library:\n"
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> GDB a -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDBHeader GDB a
gdb
    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> GDB a -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDBLib GDB a
gdb

-- | Convert a Variable to Text
showVariable :: Variable -> Text
showVariable :: Variable -> Text
showVariable (TIScalar TINumber
tn) = TINumber -> Text
showNumber TINumber
tn
showVariable (TIVector [TINumber]
tns) =
    let nums :: [Text]
nums = (TINumber -> Text) -> [TINumber] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map TINumber -> Text
showNumber [TINumber]
tns
    in Text
"<" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
intercalate Text
"," [Text]
nums Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
">"
showVariable (TIList [TINumber]
tns) =
    let nums :: [Text]
nums = (TINumber -> Text) -> [TINumber] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map TINumber -> Text
showNumber [TINumber]
tns
    in Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
intercalate Text
"," [Text]
nums Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
showVariable (TIMatrix [[TINumber]]
tnss) =
    let rows :: [Text]
rows = [ Text -> [Text] -> Text
intercalate Text
"," ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (TINumber -> Text) -> [TINumber] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map TINumber -> Text
showNumber [TINumber]
row | [TINumber]
row <- [[TINumber]]
tnss ]
    in Text
"<<" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
intercalate Text
"\n  " [Text]
rows Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
">>"
showVariable (TIConstant TINumber
tn) = TINumber -> Text
showNumber TINumber
tn
showVariable (TIEquation Text
txt) = Text
txt
showVariable (TIString Text
txt) = Text
txt
showVariable (TIProgram Program
pro) = Program -> Text
showProgram Program
pro
showVariable (TIPicture TIBitmap
pic) = TIBitmap -> Text
showAsciiArt TIBitmap
pic
showVariable (TIFuncSettings FuncSettings
settings) = FuncSettings -> Text
showFuncSettings FuncSettings
settings
showVariable (TIPolarSettings PolarSettings
settings) = PolarSettings -> Text
showPolarSettings PolarSettings
settings
showVariable (TIParamSettings ParamSettings
settings) = ParamSettings -> Text
showParamSettings ParamSettings
settings
showVariable (TIDiffEqSettings DiffEqSettings
settings) = DiffEqSettings -> Text
showDiffEqSettings DiffEqSettings
settings
showVariable (TIZRCL SavedWinSettings
settings) = SavedWinSettings -> Text
showWinSettings SavedWinSettings
settings
showVariable (TIFuncGDB GDB 'Func
gdb) = GDB 'Func -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB 'Func
gdb
showVariable (TIPolarGDB GDB 'Polar
gdb) = GDB 'Polar -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB 'Polar
gdb
showVariable (TIParamGDB GDB 'Param
gdb) = GDB 'Param -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB 'Param
gdb
showVariable (TIDiffEqGDB GDB 'DiffEq
gdb) = GDB 'DiffEq -> Text
forall (a :: GraphMode). HasGDB a => GDB a -> Text
showGDB GDB 'DiffEq
gdb

-- * IO

-- | Print a textual representation of a Variable.
printVariable :: Variable -> IO ()
printVariable :: Variable -> IO ()
printVariable = Text -> IO ()
putStrLn(Text -> IO ()) -> (Variable -> Text) -> Variable -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Variable -> Text
showVariable