Personal tools

Questions and answers

From HaskellWiki

Revision as of 05:43, 27 January 2007 by DonStewart (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.

  • Is this a good place to ask questions? MathematicalOrchid 15:30, 18 January 2007 (UTC)
    • not yet at least. try the #haskell irc channel on freenode which is usually manned by at least a few very helpfull people. alternatively try the haskell-cafe mailing list --Johannes Ahlmann 12:29, 22 January 2007 (UTC)

Hmm, that sounded like a 'no'... OK, I'm going to add a few 'real' questions, and see if that gets any more of a response... MathematicalOrchid 11:47, 22 January 2007 (UTC)

  • 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)
  • Haskell apparently allows you to write functions with bizarre names like '++' or '***'. What are the rules for this? Which characters can or can't you use? Are you required to give a fixity declaration first, or can you just use them? MathematicalOrchid 11:47, 22 January 2007 (UTC)
    • please refer 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
      "!#$%&*+./<=>?@\^|-~"
      (plus a special case involving
      (:)
      ). lacking fixity declarations, the default fixity is left associative and most tightly binding (9). --Johannes Ahlmann 12:29, 22 January 2007 (UTC)
      • Right. So I can't name my function '~', but I can name it something that has '~' in it then. I also see from the spec document that apparently only data constructors can start with ':'. (I didn't know that... Well worth knowing!) MathematicalOrchid 15:52, 22 January 2007 (UTC)
        • no, '~' is a valid operator ('one or more of "...~..."'). and you can't mix special characters with non-special characters (letter, digits, single quote, underscore).
  • GHC can do all sorts of program optimisations. But, for a given program, how can you tell what it really did when it compiled? Did it inline that function? Was that operation optimised into an in-place update? Is there a way to tell? (Short of using a disassembler that is!) MathematicalOrchid 11:47, 22 January 2007 (UTC)
  • Is there a way to make a Haskell program utilise multiple CPUs? (I rephrase: clearly this is very possible theoretically. What I mean is does any known compiler provide a way to do this?) MathematicalOrchid 11:47, 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)


Just a quick one... Can somebody explain this baffling behaviour to me?

Hugs> do fs <- getDirectoryContents "C:/" ; print fs
["WINDOWS","boot.ini"]
 
Hugs> do fs <- getDirectoryContents "C:\\" ; print fs
["WINDOWS","boot.ini"]
 
Hugs> do x <- doesDirectoryExist "C:/" ; print x
False
 
Hugs> do x <- doesDirectoryExist "C:\\" ; print x
False

Am I stupid or something? MathematicalOrchid 16:32, 26 January 2007 (UTC)

The Wiki isn't a general forum. Questions like this should be directed to either the haskell-cafe mailing list, or the irc channel. To get the most out of the Haskell community I encourage you to use these standard resources. dons 05:43, 27 January 2007 (UTC)