Personal tools

Questions and answers

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(Category:FAQ)
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Feel free to ask your questions here. Please sign your question using four tildes (<nowiki>~~~~</nowiki>). Questions and answers will be organised as they are added, and linked from here. We don't have much here yet, but [http://www.haskell.org/hawiki/HaskellNewbie the Haskell Newbie page] on the old wiki has quite a few questions and answers you can look through.
+
Feel free to ask your questions here. Please sign your question using four tildes (<nowiki>~~~~</nowiki>). Questions and answers will be organised as they are added, and linked from here.
   
 
[[Category:Community]]
 
[[Category:Community]]
Line 7: Line 7:
   
 
;Q. What are the best place to ask beginner questions?
 
;Q. What are the best place to ask beginner questions?
:A. The [http://haskell.org/pipermail/haskell-cafe/ haskell-cafe] mailing list, or the [http://haskell.org/haskellwiki/IRC_channel #haskell irc channel].
+
:A. The [http://www.haskell.org/pipermail/beginners/ beginners] mailing list, the [http://haskell.org/pipermail/haskell-cafe/ haskell-cafe] mailing list, or the [http://haskell.org/haskellwiki/IRC_channel #haskell irc channel].
   
 
;Q. Symbols are valid in Haskell function names. What are the rules for which characters can be used?
 
;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 [http://haskell.org/onlinereport/lexemes.html#ids "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 '<hask>!#$%&*+./<=>?@\^|-~</hask>'. Constructors can be operator names, so long as they start with a '<hask>:</hask>' (e.g., <hask>:+</hask> for <hask>Data.Complex</hask>). Lacking fixity declarations, the default [http://haskell.org/onlinereport/decls.html#sect4.4.2 fixity] is left associative and most tightly binding (9).
+
:A. Refer to the [[Language and library specification]] under [http://haskell.org/onlinereport/lexemes.html#ids "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 '<hask>!#$%&*+./<=>?@\^|-~</hask>'. Constructors can be operator names, so long as they start with a '<hask>:</hask>' (e.g., <hask>:+</hask> for <hask>Data.Complex</hask>).
   
 
;Q. Are fixity declarations required for functions defined with symbol names?
 
;Q. Are fixity declarations required for functions defined with symbol names?
:A. No.
+
:A. No. The default fixity is infixl 9.
   
 
;Q. GHC does a wide variety of optimisations. How can I view the optimisaitons that are performed?
 
;Q. GHC does a wide variety of optimisations. How can I view the optimisaitons that are performed?

Revision as of 01:08, 2 October 2010

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.

1 Questions and answers

Q. What are the best place to ask beginner questions?
A. The beginners mailing list, 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
).
Q. Are fixity declarations required for functions defined with symbol names?
A. No. The default fixity is infixl 9.
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?
A. Provided you are ok with the simple permissive license, you can put it here on the wiki. To do that, you must first create a login. Once that is done, start a page for your project. (People often add a link to their projects from their wiki home page.) Before starting the page, check out the guidelines for pages. If you need it, there is also help on editing wiki pages. Finally, don't forget to categorize your new page.
Q. I have a simple function; it behaves like
map
, but also threads state through the computation. Is there a standard library function that does the same thing?
A. Yes.
mapAccumL
. You could also use a state monad.

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)