I am new to haskell.
I know that I can use a tuple operator as a function: (,) 1 2.
Can I do the same with the list range ..? As in [0..9]. Or is it not a function?
Basically I have two values that I need to create a list from. The explicit lambda expression works: \x y -> [x..y]. I was trying to figure out how to make it shorter.
You can't do this with .., as it's a syntactic element built into the language rather than a function. However, there is a function that does the same thing as "(..)" or your \x y -> [x..y] would do: enumFromTo.
Its enumFromTo:
Prelude> :t enumFromTo
enumFromTo :: Enum a => a -> a -> [a]
Prelude> enumFromTo 1 5
[1,2,3,4,5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With