What does Elm mean?

I look at the zip example at http://elm-lang.org/examples/zip and I have a question about what exactly _ means in Elm.

 zip : List a -> List b -> List (a,b) zip xs ys = case (xs, ys) of ( x :: xs', y :: ys' ) -> (x,y) :: zip xs' ys' (_, _) -> [] 

My guess is that it means “everything else”, but does it mean any real meaning? What if no value?

+5
source share
1 answer

_ used to match everything where you are not interested in the meaning, so it is usually used to match the “everything else” case.

In your example, the code (_, _) will match any tuple with two values ​​in it. Note that it can also be replaced with just _ , since you don't care about any value. A more obvious example would be that you need one value from the tuple, but not another, for example, the implementation of fst in the base package

 fst : (a,b) -> a fst (a,_) = a 

We don’t care about the second value in the tuple, so it just matches _ in that position.

Elm does not have null or undefined , so you don’t have to worry about “no value” (if something doesn’t matter, Maybe ).

+8
source

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


All Articles