Duck type in Elixir

3

[5,a,15] = [5,10,15] Making this type of assignment in Elixir is duck typing  or are they different concepts?

I ask because I was left with the doubt since on the left side it is declared a "variable" without an explicit type or a direct assignment value.

    
asked by anonymous 05.11.2017 / 02:44

1 answer

4

You are assigning a list with 3 values to a list with elements, two of them are values, so it does not make sense to use them as such. The only element that serves some purpose is the a variable. Then 10 will be assigned to a and you can use this variable later with this value.

In fact, Elixir defines this as pattern matching forever.

The variable a does not have a defined type because Elixir is a dynamic typing language. The value she keeps is that she has a type. This type is defined according to the syntax used, so it is inferred by its structure.

See more about typing .

Then the second element of the list on the left is a variable that will save the value that is in the second element of the list on the right. Your type is an integer inferred by the way it is structured (written).

Elixir does not say it implements duck typing . Good, I respect this.

I do not really like the term. It seems that nobody knows what this really means and each one has its version, most of them do not add anything to what already exists and do not indicate that this has to do with typing system. So you better forget that term, which is cute, but it's no good at all in terms of engineering.

In any case, nothing indicates that you are using this according to most settings.

    
05.11.2017 / 21:02