Frage

I am new in Haskell programming. I am trying to understand syntax and semantics of this language. I am a bit curious about the semantics of grave accent . Why does this code work when we use grave accent?

elem' :: (Eq a) => a -> [a] -> Bool  
elem' a [] = False  
elem' a (x:xs)  
    | a == x    = True  
    | otherwise = a `elem'` xs {-grave accent used in this line -}
War es hilfreich?

Lösung

The backquotes are used to treat any binary function as an infix operator.

a `elem'` xs

is identical to

elem' a xs

It is the complement to the use of (+) to use a binary operator as a function:

(+) 3 5

is identical to

3 + 5
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top