Difference between revisions of "Questions and answers"

From HaskellWiki
Jump to navigation Jump to search
m (removed rants)
m (Fixed typo)
(20 intermediate revisions by 10 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]]
  +
[[Category:FAQ]]
   
  +
== Questions and answers ==
* Is this a good place to ask questions? [[User:MathematicalOrchid|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 [http://haskell.org/pipermail/haskell-cafe/ haskell-cafe] mailing list --[[User:JohannesAhlmann|Johannes Ahlmann]] 12:29, 22 January 2007 (UTC)
 
*** I tried the IRC channel. 300+ people and nobody speaking. Not very helpful. [[User:MathematicalOrchid|MathematicalOrchid]] 13:23, 22 January 2007 (UTC)
 
   
  +
;Q. What are the best places to ask beginner questions?
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... [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
  +
: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?
* Which is faster? <hask>putStr (xs ++ ys ++ xs)</hask> or <hask>putStr xs; putStr ys; putStr zs</hask>? How much of a difference does it make? [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
 
: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>).
** hmm, <hask>(++)</hask> 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... --[[User:JohannesAhlmann|Johannes Ahlmann]] 12:29, 22 January 2007 (UTC)
 
*** <hask>(++)</hask> is right-associative when there's several, resulting in the fastest possible performance. (I understand this is why the <hask>Show</hask> class is so damn weird...) Even so, I wonder if it's more efficient to join strings or use real I/O... [[User:MathematicalOrchid|MathematicalOrchid]] 13:23, 22 January 2007 (UTC)
 
   
  +
;Q. Are fixity declarations required for functions defined with symbol names?
* 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? [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
  +
:A. No. The default fixity is infixl 9.
** please refer 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> (plus a special case involving <hask>(:)</hask>). lacking fixity declarations, the default [http://haskell.org/onlinereport/decls.html#sect4.4.2 fixity] is left associative and most tightly binding (9). --[[User:JohannesAhlmann|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!) [[User:MathematicalOrchid|MathematicalOrchid]] 15:52, 22 January 2007 (UTC)
 
   
  +
;Q. GHC does a wide variety of optimisations. How can I view the optimisaitons that are performed?
* 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!) [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
** you can look at [http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#keeping-intermediates intermediate compiler outputs] with ghc flags. --[[User:JohannesAhlmann|Johannes Ahlmann]] 12:29, 22 January 2007 (UTC)
+
:A. Keep around the [http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#keeping-intermediates intermediate compiler outputs] using --keep-tmp-files or -ddump-simpl.
*** Right. So there's various bits of info you can get out of it. (All a bit low-level... but then, what would you expect?) [[User:MathematicalOrchid|MathematicalOrchid]] 15:52, 22 January 2007 (UTC)
 
   
  +
;Q. Can I use multiple CPUs with a Haskell program?
* 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?) [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
** * yes, ghc 6.6 supports multiple CPUs. see [[GHC/Concurrency#Multiprocessor_GHC]] --[[User:JohannesAhlmann|Johannes Ahlmann]] 12:29, 22 January 2007 (UTC)
+
:A. Yes, GHC 6.6 supports symmetric multicore processing. see [[GHC/Concurrency#Multiprocessor GHC]]
  +
*** Right... so I just need to compile my program with "-threaded" and run it with "+RTS -N2" or whatever? [[User:MathematicalOrchid|MathematicalOrchid]] 15:52, 22 January 2007 (UTC)
 
  +
;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 [[HaskellWiki:Copyrights | simple permissive license]], you can put it here on the wiki. To do that, you must first [[Special:Userlogin |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 [[HaskellWiki:Guidelines | guidelines for pages]]. If you need it, there is also [[Help:Editing | help on editing wiki pages]]. Finally, don't forget to categorize your new page.
  +
  +
;Q. I have a simple function; it behaves like <hask>map</hask>, but also threads state through the computation. Is there a standard library function that does the same thing?
  +
:A. Yes. <hask>mapAccumL</hask>. You could also use a state monad.
  +
  +
== Uncategorised questions ==
  +
 
* Which is faster? <hask>putStr (xs ++ ys ++ xs)</hask> or <hask>putStr xs; putStr ys; putStr zs</hask>? How much of a difference does it make? [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
 
** hmm, <hask>(++)</hask> 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... --[[User:JohannesAhlmann|Johannes Ahlmann]] 12:29, 22 January 2007 (UTC)
 
*** <hask>(++)</hask> is right-associative when there's several, resulting in the fastest possible performance. (I understand this is why the <hask>Show</hask> class is so damn weird...) Even so, I wonder if it's more efficient to join strings or use real I/O... [[User:MathematicalOrchid|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? [[User:MathematicalOrchid|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? [[User:MathematicalOrchid|MathematicalOrchid]] 11:47, 22 January 2007 (UTC)
** have a look at [[Libraries_and_tools/GUI_libraries]]. i'd have a look at [http://haskell.org/graphics/ HGL], [http://haskell.org/HOpenGL/ HOpenGL] and/or [http://haskell.org/gtk2hs/ gtk2hs]. of these, at least gtk2hs has some image handling routines. for pure image format libraries there's unfortunately a little less :(
+
** have a look at [[Libraries and tools/GUI libraries]]. i'd have a look at [http://haskell.org/graphics/ HGL], [http://haskell.org/HOpenGL/ HOpenGL] and/or [http://haskell.org/gtk2hs/ 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. [[User:MathematicalOrchid|MathematicalOrchid]] 15:52, 22 January 2007 (UTC)
 
*** 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. [[User:MathematicalOrchid|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. :-) [[User:MathematicalOrchid|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... [[User:MathematicalOrchid|MathematicalOrchid]] 22:10, 22 January 2007 (UTC)

Revision as of 19:55, 28 January 2014

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.

Questions and answers

Q. What are the best places 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.

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)