Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I apply list range as a function?

Tags:

haskell

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.

like image 287
akonsu Avatar asked Nov 22 '25 11:11

akonsu


2 Answers

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.

like image 90
jwodder Avatar answered Nov 25 '25 09:11

jwodder


Its enumFromTo:

Prelude> :t enumFromTo
enumFromTo :: Enum a => a -> a -> [a]
Prelude> enumFromTo 1 5
[1,2,3,4,5]
like image 22
utdemir Avatar answered Nov 25 '25 09:11

utdemir