Transitioning from Python to Haskell
Enjoyers of Python often describe the language as “executable pseudocode” – That is to say that the code closely resembles what one might write on a whiteboard. We might suggest that the phrase just as aptly describes Haskell, which was designed in the 1980s in part to serve as a standard language for code presented in papers. If you are trained in languages like Python, Java, or C, Haskell probably does not look like pseudocode you would write! But with some familiarity, that may change.
These articles present Haskell in terms of its similarities and differences from Python to help Python coders jump quickly into Haskell.
Iterators – A Python iterator is a sort of sequence that, unlike a list, computes each subsequent value only as it is needed rather than computing the entire list all at once. In simple cases, Haskell’s list type (
) fulfills a similar role. In some more complex situations, we may use a “streaming” library like
The next lessons go through all of the Python functions that return iterators. If you’re familiar with the
itertools module, these lessons will get you started quickly with Haskell’s
- Iterator slicing –
- Iteration to infinity –
- Chain –
Decorators – In Python, we can preface a function with a decorator (a line beginning with
@) to make some kind of tweak or assign some extra meaning to the decorated function. Although Haskell does not have a specific language feature that mirrors Python decorators, there are a lot of examples in Haskell that follow the same pattern.