Personal tools

Questions and answers

From HaskellWiki

Revision as of 10:38, 29 January 2007 by MathematicalOrchid (Talk | contribs)

Jump to: navigation, search

Feel free to ask your questions here. Please sign your question using four tildes (~~~~). Questions and answers will be organised as they are added, and linked from here. We don't have much here yet, but the Haskell Newbie page on the old wiki has quite a few questions and answers you can look through.

1 Questions and Answers

Q. What are the best place to ask beginner questions?
A. The haskell-cafe mailing list, or the #haskell irc channel.
Q. Symbols are valid in Haskell function names. What are the rules for which characters can be used?
A. Refer to the Language_and_library_specification under "Identifiers and Operators". Variable identifiers start with a lowercase letter, constructor identifiers with an uppercase letter and both can contain underscores, single quotes, letters and digits. Operators are formed from one or more of '
!#$%&*+./<=>?@\^|-~
'. Constructors can be operator names, so long as they start with a '
:
' (e.g.,
:+
for
Data.Complex
). Lacking fixity declarations, the default fixity is left associative and most tightly binding (9).
Q. Are fixity declarations requires for functions defined with symbol names?
A. No.
Q. GHC does a wide variety of optimisations. How can I view the optimisaitons that are performed?
A. Keep around the intermediate compiler outputs using --keep-tmp-files or -ddump-simpl.
Q. Can I use multiple CPUs with a Haskell program.
A. Yes, GHC 6.6 supports symmetric multicore processing. see GHC/Concurrency#Multiprocessor_GHC
Q. I just wrote this really cool program! Who can I show it to?
Q. I just wrote this interesting program that someone else might find useful. Where can I put it?

2 Uncategorised questions

  • Which is faster?
    putStr (xs ++ ys ++ xs)
    or
    putStr xs; putStr ys; putStr zs
    ? How much of a difference does it make? MathematicalOrchid 11:47, 22 January 2007 (UTC)
    • hmm,
      (++)
      is a very slow operation which is O(n) in the length of the first string. for short strings the difference should be small, for very long string you'll see a big difference. concrete timing depends on putStr... --Johannes Ahlmann 12:29, 22 January 2007 (UTC)
      • (++)
        is right-associative when there's several, resulting in the fastest possible performance. (I understand this is why the
        Show
        class is so damn weird...) Even so, I wonder if it's more efficient to join strings or use real I/O... MathematicalOrchid 13:23, 22 January 2007 (UTC)
  • I want to write a program that renders bitmap graphics. Is there any way to get this onto the video screen in Haskell? Is there any way to get the data saved to disk in some sane file format? MathematicalOrchid 11:47, 22 January 2007 (UTC)
    • have a look at Libraries_and_tools/GUI_libraries. i'd have a look at HGL, HOpenGL and/or gtk2hs. of these, at least gtk2hs has some image handling routines. for pure image format libraries there's unfortunately a little less :(
      • This is where it starts to get messy... I already tried using HGL from within Hugs. (Drawing 'pixels' that are really small squares.) However, once it's drawn enough pixels, I get a Dr Watson error and Hugs ungracefully terminates. (Actually, the latest version of Hugs seems to do this a lot.) So I went to compile it with GHC - and it seems GHC doesn't come with that library at all. And the page you linked says that HGL is 'currently broken on Win32'. Hmm... OK, I'm confused now. Then there's HOpenGL. (Is that the same thing as Graphics.Rendering.OpenGL, or is it seperate?) It's nice to know you can have hardware 3D acceleration if you want it, but maybe a tad overkill for just writing a bitmap to the display. Also, IIRC, doesn't OpenGL require you to open a window in a platform-specific way first? And then there's gtk2hs. I don't know if you can run Gtk on Win32... but that one looks like it might be worth investigating. MathematicalOrchid 15:52, 22 January 2007 (UTC)
      • Ah-hah! It seems that burried away in gtk2hs is a fair of functions to load and save PNG images. That will do nicely... if I can figure out how to use it. :-) MathematicalOrchid 16:08, 22 January 2007 (UTC)
        • I spoke too soon... I was looking at the cairo part. Apparently the main Gtk2hs part supports JPEG and others too. And it provides functions which look like you can plot pixels with them. Now, if I can figure out how to install this stuff... MathematicalOrchid 22:10, 22 January 2007 (UTC)