Elm - Running multiple lines in each branch

For example, in one branch I want to see how many times the number is divided by 1000, and then the initial number is passed less than this amount to the function recursively. Here is what I wrote:

if num // 1000 > 0 then
    repeat (num // 1000) (String.fromChar 'M')
    convertToRom (num % 1000)

However, when testing, I get the following error in the REPL:

> getRomNums 3500
-- TYPE MISMATCH ----------------------------------------- .\.\RomanNumerals.elm

Function `repeat` is expecting 2 arguments, but was given 4.

34|             repeat (num // 1000) (String.fromChar 'M')
35|>            convertToRom (num % 1000)

Maybe you forgot some parentheses? Or a comma?

How to write multiple lines of code for one if branch?

The unrelated side of the note: the format system makes the double slash a comment, but in Elm, the double slash is an integer. Not sure how to fix it.

+4
source share
1 answer

Elm ( , Haskell) , . , . , " " Elm, Elm, , , -. .

, :

convertToRom : Int -> String
convertToRom num =
    if num // 1000 > 0 then
        String.repeat (num // 1000) (String.fromChar 'M') ++ convertToRom (num % 1000)
    else if ...
    else
        ""

, .

+6
source

Source: https://habr.com/ru/post/1692889/


All Articles