Looking through the Haskell Prelude, I see a function const
:
const x _ = x
I can\'t seem to find anything relevant regarding t
Say you want to rotate a list. This is an idiomatic way to do so in Haskell:
rotate :: Int -> [a] -> [a]
rotate _ [] = []
rotate n xs = zipWith const (drop n (cycle xs)) xs
This function zips two arrays with the function const
, the first being an infinite cyclic array, the second being the array you started with.
const
acts as the bounds check, and uses the original array to terminate the cyclic array.
See: Rotate a list in Haskell