[Haskell-cafe] The Lisp Curse
Evan Laforge
qdunkan at gmail.com
Fri May 20 06:23:17 CEST 2011
> 2) Languages like Python make it easy to write fast performing code in a few
> lines that will read/write files, split strings, and build lists or
> dictionaries/associative arrays. There are very clever ways of doing all
> these things Haskell, but it can involve several qualified imports and time
> researching ByteStrings/Lazy ByteStrings/ByteString.Char8. It would be nice
> to have a single module that exports some common text operations via
> ByteStrings without requiring a lot of upfront research time learning to
> work with ByteStrings, and possibly a limited export of Data.Map features as
> well.
It's basically just Data.Text, Data.ByteString, Data.Map, and various
things from the prelude. The problem is that once people learn where
those things are they forget their own learning process and start
thinking its obvious and everyone should know.
Maybe a python <-> haskell equivalents cheatsheet could serve the
purpose? And you're probably a good person to do it since you haven't
forgotten the learning process yet :) You can just register on the
wiki and start adding things. Maybe the page even already exists.
E.g.:
s = open(fn).read() ==> s <- Text.readFile fn
'\n'.join(sorted(s.split('\n'))) ==> Text.unlines . List.sort . Text.lines
lineByWord = dict(tuple(line.split(':', 1)) for line in lines) ==>
lineByWord = Map.fromList [(word, rest) | line <- lines, let (word,
rest) = Text.break (==':') line]
now = datetime.datetime.now()
print '\n'.join((now - datetime.strptime(..., m)).days for m in
re.groups(r'...', line))
==> you tell me :)
Or whatever other things you are doing in python that you wish you
could do as easily in haskell.
If they're used to the above style of python, then there are pretty
direct translations for everything. If they are used to a more
imperative style then I think some upfront research time is
unavoidable, but it'll be good for them.
More information about the Haskell-Cafe
mailing list