# ELM polish calculator

**URL:** <https://discourse.elm-lang.org/t/elm-polish-calculator/7659>\
**Category:** Learn\
**Created:** [August 11, 2021, 1:37pm UTC](https://discourse.elm-lang.org/t/elm-polish-calculator/7659 "2021-08-11T13:37:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zack\_slm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/zack_slm/32/4166_2.png) [@Zack\_slm](https://discourse.elm-lang.org/u/Zack_slm)\
**Post date:** [August 11, 2021, 1:37pm UTC](https://discourse.elm-lang.org/t/elm-polish-calculator/7659/1 "2021-08-11T13:37:02Z")

</div>

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](https://ellie-app.com/dYwD6TshCtBa1)  
i have problem in (case ( inputs, digitsStack ) of ) in function getPolishSumHelper.  
can you help please

---

<div class="post-metadata">

**Author:** ![jreusch](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jreusch](https://discourse.elm-lang.org/u/jreusch)\
**Post date:** [August 11, 2021, 2:57pm UTC](https://discourse.elm-lang.org/t/elm-polish-calculator/7659/2 "2021-08-11T14:57:45Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Zack\_slm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/zack_slm/32/4166_2.png) [@Zack\_slm](https://discourse.elm-lang.org/u/Zack_slm)\
**Post date:** [August 11, 2021, 6:35pm UTC](https://discourse.elm-lang.org/t/elm-polish-calculator/7659/3 "2021-08-11T18:35:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [August 21, 2021, 6:36pm UTC](https://discourse.elm-lang.org/t/elm-polish-calculator/7659/4 "2021-08-21T18:36:08Z")

</div>

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