Why does Elm use the "++" operator to concatenate strings?

I study Elma and I find many things that are attractive in this, such as its elegance and simplicity. However, one aspect that I find cryptic is the use of "++" to concatenate strings. For instance:

> "hello" ++ " world"
"hello world"

The add-on works as you expected.

> 2 + 3 + 9
14

Most high-level languages, such as C # / Java / JavaScript / Python, use one plus "+" in string concatenation in the same way to sum multiple numbers. This seems much more intuitive, as there is some consistency in the concatenation of strings, such as the sum of numbers.

Does anyone know the design decision logic to use instead of ++ in this context?

+6
source share
4 answers

Elm allows you to define polymorphic functions.

Parametric polymorphism is when a function can be applied to elements of any type:

f : (a, b) -> (b, a)
f (x, y) = (y, x)

Ad-hoc polymorphism is when a function can be applied to elements of certain types:

g : appendable -> appendable -> appendable -> appendable
g x y z = x ++ y ++ z

h : number -> number -> number
h x y = (x + 2) * y

Variables of type numberand appendableare special because they are a subset of all types of Elm. Listand Stringare appendable, while Floatand Intare the types of numbers.

hasPlus, List, String, Float Int, , , x + y y + x, , ...

+9

, .

, , ( , ++ if +).

, ( , ELM), , , .

XQuery || + , , +. CAML.

+6

- . , ( , ), . - , .

, - ?

number:

(+) : number -> number -> number

numberorstring, + , .

+5

docs ++ :

-- alias for appending lists and two lists
append xs ys = xs ++ ys
xs = [1,2,3]
ys = [4,5,6]

-- All of the following expressions are equivalent:
a1 = append xs ys
a2 = xs ++ ys

b2 = (++) xs ys

c1 = (append xs) ys
c2 = ((++) xs) ys

0.9 , Haskell. 0.9 (. ), , ++, , .

+4

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


All Articles