ELM polish calculator

hello,
i try to code polish calculator

  • 5 8 = 5 * 8 = 40
    i try to get an input (String) then calculate and return an output(String), if i have an error i will return “ERROR” else a string with result.
    this my code : https://ellie-app.com/dYwD6TshCtBa1
    i have problem in (case ( inputs, digitsStack ) of ) in function getPolishSumHelper.
    can you help please

You deleted the case that returns the final result. You may want to check out @wolfadex 's solution again.

Btw, I do not think replacing the Result String String with just a String is the right call here. Elm is really good at modelling the exact data types you are dealing with. Moving everything to String is the opposite approach - it gets you closer to something you would write in Javascript for example. This is commonly called a “stringly typed” system. Doing so makes everything harder to understand and maintain, since it is extremly easy to just mix up 2 completely unrelated values.

I would try to get towards these types:

type Operator
  = Add
  | Subtract
  | Multiply
  | Divide

type Input
  = Operator Operator
  | Number Int


type Problem
  = InvalidOperator String
  | InvalidNumber String
  | NoNumbersForOperator
  | SingleNumberForOperator
  | MoreThanOneInputLeft


parsePolishNotation : String -> Result Problem (List Input)
getPolishSumHelper : List Input  -> List Int -> Result Problem Int
calcNext : Operator -> List Input -> Int -> Int -> List Int -> Int

Hello, thank you for your tips, I understand but I need result to be à String and input to be à String

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.