4 ms·
I haven't seen this Haskell syntax before: [1,3..10] ⇔ [1,3,5,7,9] Imagine running into this one on a production system... Someone needs to make a 'Haskell:
by RyanZAG 13y ago
I haven't seen this Haskell syntax before:
[1,3..10] ⇔ [1,3,5,7,9]
Imagine running into this one on a production system... Someone needs to make a 'Haskell: the good parts' or at least a lint.
- merijnv 13y agoHow is that weird, it's just uses the increment from the first to second value as step and repeat as long as it's smaller than the end value. Python does the exact same thing: Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> range(1, 10, 2) [1, 3, 5, 7, 9]
- deleted 13y ago[deleted]
- pja 13y agoYou'll see that in a lot of languages that include list comprehensions as part of their syntax.
- freyrs3 13y ago> Someone needs to make a 'Haskell: the good parts' or at least a lint. Someone needs to write a book about the good parts because you haven't learned the language? It's documented right in the Prelude[1] what this desugars into. http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:enumFromThenTo http://www.haskell.org/ghc/docs/latest/html/libraries/base/P...
- nbouscal 13y agoThere is a linter, called hlint, which is extremely useful. It doesn't flag that, though, nor do I see any reason it should.
- Tehnix 13y agoAre you implying it's complex? Because a lot of languages have list comprehensions[1] (list comprehensions are awesome!). Haskells is very close to the mathmatical set-builder notation[2]. An example of a more advanced one would be >> [2*x | x <- [0,1..25], x^2 `rem` 3 == 0] [0,6,12,18,24,30,36,42,48] Also, there is HLint for Haskell linting purposes... [1] http://en.wikipedia.org/wiki/List_comprehension#Examples_in_different_programming_languages http://en.wikipedia.org/wiki/List_comprehension#Examples_in_... [2] http://en.wikipedia.org/wiki/Set-builder_notation#Parallels_in_programming_languages http://en.wikipedia.org/wiki/Set-builder_notation#Parallels_...