clac-gtk

Maintaineralexander@plaimi.net
Safe HaskellSafe-Inferred

Clac

Description

 

Synopsis

Documentation

data Opt Source

Holds information about the user passed options.

Constructors

MkOpt 

data StackItem a whereSource

An item on the calculator stack. Can either be a constant number, or an operator.

Constructors

StackNum :: forall a. Fractional a => a -> StackItem a 
StackOp :: OpDesc -> StackItem a 

Instances

Show a => Show (StackItem a) 

data OpDesc Source

Operator-description binding.

Constructors

MkOpDesc 

Fields

op :: Op
 
desc :: String
 

Instances

data Op whereSource

The valid operator classes.

Constructors

BinaryOp :: (forall a. Fractional a => a -> a -> a) -> Op 
UnaryOp :: (forall a. Floating a => a -> a) -> Op 
Constant :: (forall a. Floating a => a) -> Op 
NewEq :: Op 

optParser :: Parser OptSource

Parser for the user requested options.

operators :: [(OpDesc, String)]Source

Predefined operator stack. This reflects the current program features.

buildStackSource

Arguments

:: String

one equation item

-> [StackItem Double]

prepend the result to this stack

-> [StackItem Double] 

Build the calculator stack. Usually used in conjunction with foldr, to build the complete stack consecutively.

parseStackSource

Arguments

:: String

one equation item

-> Maybe (StackItem Double)

converted stack item, if valid

Parse an equation item.

stackTree :: [StackItem Double] -> Tree StringSource

Build a tree from a calculator stack, suitable for pretty printing.

solveStackSource

Arguments

:: [StackItem Double]

stack to solve

-> [StackItem Double]

stack used for zipping, initially empty

-> Maybe Double

calculation result

Solve a stack.

solveAll :: [[String]] -> [(Maybe Double, String)]Source

Solve multiple equations of an input list such as:

 [["1","1","+"],["2","2","+"]]

This gives back a tuple for each equation where the first value is the result of the equation (if any) and the second one is a String representing the stackTree, suitable for printing.

solveEquation :: String -> Maybe DoubleSource

Solve an equation of the form 1 2 +.