Double exclamation marks in Haskell

Might find it easier to think in equivilances

let listOfFuns = map (*) [0..] in (listOfFuns !! 4) 5
== (map (*) [0..] !! 4) 5
== (map (*) [0, 1, 2, ...] !! 4) 5
== ([(0*), (1*), (2*), ...] !! 4) 5
== (4*) 5
== 20

You can see here map (*) [0..] is a [Int → Int], so when you take the 3rd element of it (which is what !! 4 does) you get a function Int → Int. Finally 5 is applied to that function to give you 20.


!! indexes lists. It takes a list and an index, and returns the item at that index. If the index is out of bounds, it returns ⊥.

Tags:

Haskell