https://wiki.haskell.org/api.php?action=feedcontributions&user=Keegan&feedformat=atomHaskellWiki - User contributions [en]2024-03-29T00:40:39ZUser contributionsMediaWiki 1.35.5https://wiki.haskell.org/index.php?title=Hac_Boston/Talks&diff=44112Hac Boston/Talks2012-01-21T10:04:00Z<p>Keegan: </p>
<hr />
<div>== Talks == <br />
<br />
{| class="wikitable"<br />
! Talk Name<br />
! Speaker<br />
|-<br />
| What Happened to Category Extras?<br />
| Edward Kmett<br />
|-<br />
| More expressive types for orders and intervals<br />
| Doug McClean<br />
|-<br />
| First-Class Differential Equations<br />
| Gershom Bazerman <br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Talks&diff=44089Hac Boston/Talks2012-01-20T08:53:51Z<p>Keegan: </p>
<hr />
<div>== Talks == <br />
<br />
{| class="wikitable"<br />
! Talk Name<br />
! Speaker<br />
|-<br />
| What Happened to Category Extras?<br />
| Edward Kmett<br />
|-<br />
| to be determined?<br />
| Keegan McAllister<br />
|-<br />
| More expressive types for orders and intervals<br />
| Doug McClean<br />
|-<br />
| First-Class Differential Equations<br />
| Gershom Bazerman <br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=44044Hac Boston2012-01-19T20:07:10Z<p>Keegan: /* By public transit */ add building 66 option</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology], rooms '''4-159''' and '''4-261'''. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
Not to be confused with [http://www.hac.org.uk/html/about-the-hac/hac-clubs-societies/boston-association/?PHPSESSID=9ed42c54191317cd20 HAC Boston].<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
We have room for approximately 80 people, and have just under 50 people registered so far. If you plan to be in the area and are thinking about attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ] and [http://www.nowbi.com/ Now Business Intelligence].<br />
<br />
== Dates and Times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some [[/Talks|talks]] Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Maps ==<br />
<br />
We have a Google map regarding [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation and places to stay], and another with [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c points of interest around Cambridge].<br />
<br />
The hackathon itself is in Building 4 spread between rooms 159 and 261. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
From the Kendall stop on the Red Line, you will need to make your way to [http://whereis.mit.edu/?go=4 building 4]. You'll exit on Main St, and you want to go south. For reference, the Marriott and other large buildings are arranged around a courtyard ''north'' of Main St.<br />
<br />
Next to the subway exit and the MIT Press Bookstore, there is a path which quickly becomes Carleton St. Follow Carleton south past MIT Medical (and maybe some tasty food trucks) until you're forced to veer right onto Amherst St. Continue straight off the end of Amherst, passing the [http://upload.wikimedia.org/wikipedia/en/f/f4/MIT-Green-Building.jpg tall Green Building and the pointy metal sculpture]. Eventually your path will be obstructed by the interconnected complex of buildings 2, 4, and 6. Go inside and make your way to 4-159. The local inhabitants are friendly and will be happy to point you in the right direction if you get lost.<br />
<br />
See also the line drawn on the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation map].<br />
<br />
You could instead cut through MIT Medical and cross Ames St. to enter building 66 (the triangular one). From there you can get to building 4 following interior hallways only. This could be a better option if the weather is terrible.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=44043Hac Boston2012-01-19T19:55:31Z<p>Keegan: /* By public transit */ change walking directions</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology], rooms '''4-159''' and '''4-261'''. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
Not to be confused with [http://www.hac.org.uk/html/about-the-hac/hac-clubs-societies/boston-association/?PHPSESSID=9ed42c54191317cd20 HAC Boston].<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
We have room for approximately 80 people, and have just under 50 people registered so far. If you plan to be in the area and are thinking about attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ] and [http://www.nowbi.com/ Now Business Intelligence].<br />
<br />
== Dates and Times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some [[/Talks|talks]] Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Maps ==<br />
<br />
We have a Google map regarding [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation and places to stay], and another with [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c points of interest around Cambridge].<br />
<br />
The hackathon itself is in Building 4 spread between rooms 159 and 261. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
From the Kendall stop on the Red Line, you will need to make your way to [http://whereis.mit.edu/?go=4 building 4]. You'll exit on Main St, and you want to go south. For reference, the Marriott and other large buildings are arranged around a courtyard ''north'' of Main St.<br />
<br />
Next to the subway exit and the MIT Press Bookstore, there is a path which quickly becomes Carleton St. Follow Carleton south past MIT Medical (and maybe some tasty food trucks) until you're forced to veer right onto Amherst St. Continue straight off the end of Amherst, passing the [http://upload.wikimedia.org/wikipedia/en/f/f4/MIT-Green-Building.jpg tall Green Building and the pointy metal sculpture]. Eventually your path will be obstructed by the interconnected complex of buildings 2, 4, and 6. Go inside and make your way to 4-159. The local inhabitants are friendly and will be happy to point you in the right direction if you get lost.<br />
<br />
See also the line drawn on the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation map].<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Foldr_Foldl_Foldl%27&diff=43624Foldr Foldl Foldl'2011-12-15T13:57:40Z<p>Keegan: more on strictness</p>
<hr />
<div>__NOTOC__<br />
<br />
To ''foldr'', ''foldl'' or ''foldl''' that's the question! This article demonstrates the differences between these different folds by a simple example.<br />
<br />
If you want you can copy/paste this article into your [http://haskell.org/haskellwiki/Haskell_mode_for_Emacs favorite editor] and run it.<br />
<br />
We are going to define our own folds so we hide the ones from the Prelude:<br />
<br />
<haskell>> import Prelude hiding (foldr, foldl)</haskell><br />
<br />
==Foldr==<br />
<br />
Say we want to calculate the sum of a very big list:<br />
<br />
<haskell>> veryBigList = [1..1000000]</haskell><br />
<br />
Lets start with the following:<br />
<br />
<haskell><br />
> foldr f z [] = z<br />
> foldr f z (x:xs) = x `f` foldr f z xs<br />
<br />
> sum1 = foldr (+) 0<br />
<br />
> try1 = sum1 veryBigList<br />
</haskell><br />
<br />
If we evaluate ''try1'' we get:<br />
<br />
<tt><nowiki>*** Exception: stack overflow</nowiki></tt><br />
<br />
Too bad... So what happened:<br />
<haskell><br />
try1 --><br />
sum1 veryBigList --><br />
foldr (+) 0 veryBigList --><br />
<br />
foldr (+) 0 [1..1000000] --><br />
1 + (foldr (+) 0 [2..1000000]) --><br />
1 + (2 + (foldr (+) 0 [3..1000000])) --><br />
1 + (2 + (3 + (foldr (+) 0 [4..1000000]))) --><br />
1 + (2 + (3 + (4 + (foldr (+) 0 [5..1000000])))) --><br />
-- ...<br />
-- ... My stack overflows when there's a chain of around 500000 (+)'s !!!<br />
-- ... But the following would happen if you got a large enough stack:<br />
-- ...<br />
1 + (2 + (3 + (4 + (... + (999999 + (foldr (+) 0 [1000000]))...)))) --><br />
1 + (2 + (3 + (4 + (... + (999999 + (1000000 + ((foldr (+) 0 []))))...)))) --><br />
<br />
1 + (2 + (3 + (4 + (... + (999999 + (1000000 + 0))...)))) --><br />
1 + (2 + (3 + (4 + (... + (999999 + 1000000)...)))) --><br />
1 + (2 + (3 + (4 + (... + 1999999 ...)))) --><br />
<br />
1 + (2 + (3 + (4 + 500000499990))) --><br />
1 + (2 + (3 + 500000499994)) --><br />
1 + (2 + 500000499997) --><br />
1 + 500000499999 --><br />
500000500000<br />
</haskell><br />
<br />
The problem is that (+) is strict in both of its arguments. This means that both arguments must be fully evaluated before (+) can return a result. So to evaluate:<br />
<br />
<haskell>1 + (2 + (3 + (4 + (...))))</haskell><br />
<br />
<tt>1</tt> is pushed on the stack. Then:<br />
<br />
<haskell>2 + (3 + (4 + (...)))</haskell><br />
<br />
is evaluated. So <tt>2</tt> is pushed on the stack. Then:<br />
<br />
<haskell>3 + (4 + (...))</haskell><br />
<br />
is evaluated. So <tt>3</tt> is pushed on the stack. Then:<br />
<br />
<haskell>4 + (...)</haskell><br />
<br />
is evaluated. So <tt>4</tt> is pushed on the stack. Then: ... <br />
<br />
... your limited stack will eventually run full when you evaluate a large enough chain of (+)s. This then triggers the stack overflow exception.<br />
<br />
Lets think about how to solve it... <br />
<br />
==Foldl==<br />
<br />
One problem with the chain of (+)'s is that we can't make it<br />
smaller (reduce it) until at the very last moment when it's already<br />
too late.<br />
<br />
The reason we can't reduce it, is that the chain doesn't contain an<br />
expression which can be reduced (a so called "redex" for '''red'''ucible<br />
'''ex'''pression.) If it did we could reduce that expression before going<br />
to the next element.<br />
<br />
Well, we can introduce a redex by forming the chain in another way. If<br />
instead of the chain <tt>1 + (2 + (3 + (...)))</tt> we could form the chain<br />
<tt>(((0 + 1) + 2) + 3) + ...</tt> then there would always be a redex.<br />
<br />
We can form the latter chain by using a function called ''foldl'':<br />
<br />
<haskell><br />
> foldl f z [] = z<br />
> foldl f z (x:xs) = let z' = z `f` x <br />
> in foldl f z' xs<br />
<br />
> sum2 = foldl (+) 0<br />
<br />
> try2 = sum2 veryBigList<br />
</haskell><br />
<br />
Lets evaluate ''try2'':<br />
<br />
<tt><nowiki>*** Exception: stack overflow</nowiki></tt><br />
<br />
Good Lord! Again a stack overflow! Lets see what happens:<br />
<br />
<haskell><br />
try2 --><br />
sum2 veryBigList --><br />
foldl (+) 0 veryBigList --><br />
<br />
foldl (+) 0 [1..1000000] --><br />
<br />
let z1 = 0 + 1<br />
in foldl (+) z1 [2..1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
in foldl (+) z2 [3..1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
in foldl (+) z3 [4..1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
in foldl (+) z4 [5..1000000] --><br />
<br />
-- ... after many foldl steps ...<br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
in foldl (+) z999997 [999998..1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
in foldl (+) z999998 [999999..1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
z999999 = z999998 + 999999<br />
in foldl (+) z999999 [1000000] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
z999999 = z999998 + 999999<br />
z100000 = z999999 + 1000000<br />
in foldl (+) z1000000 [] --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
z999999 = z999998 + 999999<br />
z100000 = z999999 + 1000000<br />
in z1000000 --><br />
<br />
-- Now a large chain of +'s will be created:<br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
z999999 = z999998 + 999999<br />
in z999999 + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
in (z999998 + 999999) + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
in ((z999997 + 999998) + 999999) + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
in (((z999996 + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
-- ...<br />
-- ... My stack overflows when there's a chain of around 500000 (+)'s !!!<br />
-- ... But the following would happen if you got a large enough stack:<br />
-- ...<br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
in (((((z4 + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
in ((((((z3 + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
in (((((((z2 + 3) + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
let z1 = 0 + 1<br />
in ((((((((z1 + 2) + 3) + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
(((((((((0 + 1) + 2) + 3) + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
-- Now we can actually start reducing:<br />
<br />
((((((((1 + 2) + 3) + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
(((((((3 + 3) + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
((((((6 + 4) + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
(((((10 + 5) + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
((((15 + ...) + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
(((499996500006 + 999997) + 999998) + 999999) + 1000000 --><br />
<br />
((499997500003 + 999998) + 999999) + 1000000 --><br />
<br />
(499998500001 + 999999) + 1000000 --><br />
<br />
499999500000 + 1000000 --><br />
<br />
500000500000 --><br />
</haskell><br />
<br />
Well, you clearly see that the redexen are created. But instead of being directly reduced, they are allocated on the heap:<br />
<br />
<haskell><br />
let z1 = 0 + 1<br />
z2 = z1 + 2<br />
z3 = z2 + 3<br />
z4 = z3 + 4<br />
...<br />
z999997 = z999996 + 999997<br />
z999998 = z999997 + 999998<br />
z999999 = z999998 + 999999<br />
z100000 = z999999 + 1000000<br />
in z1000000<br />
</haskell><br />
<br />
Note that your heap is only limited by the amount of memory in your system (RAM and swap). So the only thing this does is filling up a large part of your memory. <br />
<br />
The problem starts when we finally evaluate z1000000:<br />
<br />
Note that <tt>z1000000 = z999999 + 1000000</tt>.<br />
So <tt>1000000</tt> is pushed on the stack. <br />
Then <tt>z999999</tt> is evaluated. <br />
<br />
Note that <tt>z999999 = z999998 + 999999</tt>. <br />
So <tt>999999</tt> is pushed on the stack.<br />
Then <tt>z999998</tt> is evaluated:<br />
<br />
Note that <tt>z999998 = z999997 + 999998</tt>. <br />
So <tt>999998</tt> is pushed on the stack.<br />
Then <tt>z999997</tt> is evaluated:<br />
So ...<br />
<br />
...your limited stack will eventually run full when you evaluate a large enough chain of (+)s. This then triggers the stack overflow exception.<br />
<br />
But this is exactly the problem we had in the foldr case! Only now the chain of (+) is going to the left instead of going to the right.<br />
<br />
So why doesn't the chain reduce sooner than<br />
before?<br />
<br />
The answer is that GHC uses a lazy reduction strategy. This means<br />
that GHC only reduces an expression when its value is actually<br />
needed. <br />
<br />
The reduction strategy works by reducing the outer-left-most redex<br />
first. In this case it are the outer <tt>foldl (+) ... [1..10000]</tt><br />
redexen which are repeatedly reduced. <br />
So the inner <tt>z1, z2, z3, ...</tt> redexen only get reduced when<br />
the foldl is completely gone.<br />
<br />
==Foldl'==<br />
<br />
We somehow have to tell the system that the inner redex should be<br />
reduced before the outer. Fortunately this is possible with the<br />
''seq'' function:<br />
<br />
<haskell>seq :: a -> b -> b</haskell><br />
<br />
''seq'' is a primitive system function that when applied to ''x'' and<br />
''y'' will first reduce ''x'' then return ''y''. The idea is that ''y'' references ''x'' so that when ''y'' is reduced ''x'' will not be a big unreduced chain anymore.<br />
<br />
Now lets fill in the pieces:<br />
<br />
<haskell><br />
> foldl' f z [] = z<br />
> foldl' f z (x:xs) = let z' = z `f` x <br />
> in seq z' $ foldl' f z' xs<br />
<br />
> sum3 = foldl' (+) 0<br />
<br />
> try3 = sum3 veryBigList<br />
</haskell><br />
<br />
If we now evaluate ''try3'' we get the correct answer and we get it very quickly:<br />
<br />
<haskell>500000500000</haskell><br />
<br />
Lets see what happens:<br />
<br />
<haskell><br />
try3 --><br />
sum3 veryBigList --><br />
foldl' (+) 0 veryBigList --><br />
<br />
foldl' (+) 0 [1..1000000] --><br />
foldl' (+) 1 [2..1000000] --><br />
foldl' (+) 3 [3..1000000] --><br />
foldl' (+) 6 [4..1000000] --><br />
foldl' (+) 10 [5..1000000] --><br />
-- ...<br />
-- ... You see that the stack doesn't overflow<br />
-- ...<br />
foldl' (+) 499999500000 [1000000] --><br />
foldl' (+) 500000500000 [] --><br />
500000500000<br />
</haskell><br />
<br />
You can clearly see that the inner redex is repeatedly reduced<br />
first.<br />
<br />
==Conclusion==<br />
<br />
Usually the choice is between <hask>foldr</hask> and <hask>foldl'</hask>, since <hask>foldl</hask> and <hask>foldl'</hask> are the same except for their strictness properties, so if both return a result, it must be the same. <hask>foldl'</hask> is the more efficient way to arrive at that result because it doesn't build a huge thunk. However, if the combining function is lazy in its ''first'' argument, <hask>foldl</hask> may happily return a result where <hask>foldl'</hask> hits an exception:<br />
<br />
<haskell><br />
> (?) :: Int -> Int -> Int<br />
> _ ? 0 = 0<br />
> x ? y = x*y<br />
><br />
> list :: [Int]<br />
> list = [2,3,undefined,5,0]<br />
> <br />
> okey = foldl (?) 1 list<br />
><br />
> boom = foldl' (?) 1 list<br />
</haskell><br />
<br />
Let's see what happens:<br />
<br />
<haskell><br />
okey --><br />
foldl (?) 1 [2,3,undefined,5,0] --><br />
foldl (?) (1 ? 2) [3,undefined,5,0] --><br />
foldl (?) ((1 ? 2) ? 3) [undefined,5,0] --><br />
foldl (?) (((1 ? 2) ? 3) ? undefined) [5,0] --><br />
foldl (?) ((((1 ? 2) ? 3) ? undefined) ? 5) [0] --><br />
foldl (?) (((((1 ? 2) ? 3) ? undefined) ? 5) ? 0) [] --><br />
((((1 ? 2) ? 3) ? undefined) ? 5) ? 0 --><br />
0<br />
<br />
boom --><br />
foldl' (?) 1 [2,3,undefined,5,0] --><br />
1 ? 2 --> 2<br />
foldl' (?) 2 [3,undefined,5,0] --><br />
2 ? 3 --> 6<br />
foldl' (?) 6 [undefined,5,0] --><br />
6 ? undefined --><br />
*** Exception: Prelude.undefined<br />
</haskell><br />
<br />
Note that even <hask>foldl'</hask> may not do what you expect.<br />
The involved <hask>seq</hask> function does only evaluate the ''top-most constructor''.<br />
<br />
If the accumulator is a more complex object, then <hask>fold'</hask> will still build up unevaluated thunks. You can introduce a function or a strict data type which forces the values as far as you need. Failing that, the "brute force" solution is to use {{HackagePackage|id=deepseq}}. For a worked example of this issue, see [http://book.realworldhaskell.org/read/profiling-and-optimization.html#id678431 ''Real World Haskell'' chapter 25].<br />
<br />
== See also ==<br />
<br />
* [[Fold]]<br />
* [[Foldl as foldr]]<br />
<br />
[[Category:FAQ]]<br />
[[Category:Idioms]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Projects&diff=42719Hac Boston/Projects2011-11-03T10:28:47Z<p>Keegan: </p>
<hr />
<div>== Sharing your code ==<br />
<br />
If you need a place to host a project so that others can help with it, we suggest <br />
[http://github.com github], but if you are using darcs [http://patch-tag.com/ patch-tag] is just dandy as well. <br />
<br />
You can also apply for an account on <br />
[http://community.haskell.org/admin/ the community server].<br />
<br />
== Projects ==<br />
<br />
If you have a project that you want to work on at the Hackathon, please describe it here.<br />
<br />
Since Hackathons are great for teamwork, consider joining one of the projects mentioned below. If you're interested in one of these projects, add your name to the list of hackers under that project.<br />
<br />
<!-- Copy this template<br />
=== Project name ===<br />
<br />
I am a project. Love me.<br />
<br />
Interested in this project:<br />
<br />
* Hacker 1<br />
* Hacker 2<br />
--><br />
<br />
=== Trifecta ===<br />
<br />
[http://hackage.haskell.org/package/trifecta Trifecta] is a library for dealing with both parsing and the ancillary concerns that arise once you have a parser.<br />
<br />
Interested in this project:<br />
<br />
* Edward Kmett<br />
<br />
=== Machine code analysis tools ===<br />
<br />
Haskell could be a great platform for analyzing and reverse-engineering machine code. We already have disassemblers ([http://hackage.haskell.org/package/hdis86 x86], [https://github.com/copumpkin/charm ARM]), object format parsers ([http://hackage.haskell.org/package/elf ELF], [http://hackage.haskell.org/package/pecoff PE/COFF], [http://hackage.haskell.org/package/macho MachO]), SMT and [http://hackage.haskell.org/package/sbv bitvector] solvers, [http://hackage.haskell.org/package/hoopl dataflow analysis], etc. Let's improve these tools and fill in the gaps.<br />
<br />
Some concrete projects in this area:<br />
<br />
* Write bindings to [http://radare.org/ radare]<br />
* Finish up the [https://github.com/copumpkin/charm charm] disassembler for ARM, and get it on Hackage<br />
* Modify [http://hackage.haskell.org/package/elf elf] to support parsing relocation records<br />
* Add support to the object format libraries for writing data structures back out to disk<br />
* Write a format-agnostic layer on top of the object format libraries<br />
<br />
Interested in this project:<br />
<br />
* Keegan McAllister<br />
<br />
=== G-code backend for Diagrams ===<br />
<br />
[http://projects.haskell.org/diagrams Diagrams] is a nice library for declarative vector graphics. With a [http://linuxcnc.org/docs/html/gcode_main.html G-code] backend, it could be used to control industrial cutting equipment.<br />
<br />
We already have a [https://github.com/kmcallister/gcode G-code output library]. For this project we would need to render Diagrams constructs to the simpler G-code commands.<br />
<br />
Interested in this project:<br />
<br />
* Keegan McAllister<br />
<br />
== Experience ==<br />
<br />
Please list projects with which you are familiar. This way, people know whom to contact for more information or guidance on a particular project.<br />
<br />
{| class="wikitable"<br />
! Name<br />
! Projects<br />
|-<br />
| edwardk<br />
| [http://github.com/ekmett lots of projects], mtl, general libraries<br />
|-<br />
| ezyang<br />
| ghc<br />
|-<br />
| keegan<br />
| [https://github.com/kmcallister various], some GHC internals, FFI tricks<br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Projects&diff=42718Hac Boston/Projects2011-11-03T09:46:01Z<p>Keegan: </p>
<hr />
<div>== Sharing your code ==<br />
<br />
If you need a place to host a project so that others can help with it, we suggest <br />
[http://github.com github], but if you are using darcs [http://patch-tag.com/ patch-tag] is just dandy as well. <br />
<br />
You can also apply for an account on <br />
[http://community.haskell.org/admin/ the community server].<br />
<br />
== Projects ==<br />
<br />
If you have a project that you want to work on at the Hackathon, please describe it here.<br />
<br />
Since Hackathons are great for teamwork, consider joining one of the projects mentioned below. If you're interested in one of these projects, add your name to the list of hackers under that project.<br />
<br />
<!-- Copy this template<br />
=== Project name ===<br />
<br />
I am a project. Love me.<br />
<br />
* Hacker 1<br />
* Hacker 2<br />
--><br />
<br />
=== Trifecta ===<br />
<br />
[http://hackage.haskell.org/package/trifecta Trifecta] is a library for dealing with both parsing and the ancillary concerns that arise once you have a parser.<br />
<br />
* Edward Kmett<br />
<br />
=== Machine code analysis tools ===<br />
<br />
Haskell could be a great platform for analyzing and reverse-engineering machine code. We already have disassemblers ([http://hackage.haskell.org/package/hdis86 x86], [https://github.com/copumpkin/charm ARM]), object format parsers ([http://hackage.haskell.org/package/elf ELF], [http://hackage.haskell.org/package/pecoff PE/COFF], [http://hackage.haskell.org/package/macho MachO]), SMT and [http://hackage.haskell.org/package/sbv bitvector] solvers, [http://hackage.haskell.org/package/hoopl dataflow analysis], etc. Let's improve these tools and fill in the gaps.<br />
<br />
Some concrete projects in this area:<br />
<br />
* Write bindings to [http://radare.org/ radare]<br />
* Finish up the [https://github.com/copumpkin/charm charm] disassembler for ARM, and get it on Hackage<br />
* Modify [http://hackage.haskell.org/package/elf elf] to support parsing relocation records<br />
* Add support to the object format libraries for writing data structures back out to disk<br />
* Write a format-agnostic layer on top of the object format libraries<br />
<br />
Interested in this project:<br />
<br />
* Keegan McAllister<br />
<br />
== Experience ==<br />
<br />
Please list projects with which you are familiar. This way, people know whom to contact for more information or guidance on a particular project.<br />
<br />
{| class="wikitable"<br />
! Name<br />
! Projects<br />
|-<br />
| edwardk<br />
| [http://github.com/ekmett lots of projects], mtl, general libraries<br />
|-<br />
| ezyang<br />
| ghc<br />
|-<br />
| keegan<br />
| [https://github.com/kmcallister various], some GHC internals, FFI tricks<br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Projects&diff=42716Hac Boston/Projects2011-11-03T09:00:22Z<p>Keegan: /* Experience */</p>
<hr />
<div>== Sharing your code ==<br />
<br />
If you need a place to host a project so that others can help with it, we suggest <br />
[http://github.com github], but if you are using darcs [http://patch-tag.com/ patch-tag] is just dandy as well. <br />
<br />
You can also apply for an account on <br />
[http://community.haskell.org/admin/ the community server].<br />
<br />
== Projects ==<br />
<br />
If you have a project that you want to work on at the Hackathon, please describe it here.<br />
<br />
Since Hackathons are great for teamwork, consider joining one of the projects mentioned below. If you're interested in one of these projects, add your name to the list of hackers under that project.<br />
<br />
<!-- Copy this template<br />
=== Project name ===<br />
<br />
I am a project. Love me.<br />
<br />
* Hacker 1<br />
* Hacker 2<br />
--><br />
<br />
=== Trifecta ===<br />
<br />
[http://hackage.haskell.org/package/trifecta Trifecta] is a library for dealing with both parsing and the ancillary concerns that arise once you have a parser.<br />
<br />
* Edward Kmett<br />
<br />
== Experience ==<br />
<br />
Please list projects with which you are familiar. This way, people know whom to contact for more information or guidance on a particular project.<br />
<br />
{| class="wikitable"<br />
! Name<br />
! Projects<br />
|-<br />
| edwardk<br />
| [http://github.com/ekmett lots of projects], mtl, general libraries<br />
|-<br />
| ezyang<br />
| ghc<br />
|-<br />
| keegan<br />
| [https://github.com/kmcallister various], some GHC internals, FFI tricks<br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42598Hac Boston2011-10-27T09:47:42Z<p>Keegan: /* Dates and times */</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some [[/Talks|talks]] Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Maps ==<br />
<br />
We have a Google map regarding [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation and places to stay], and another with [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c points of interest around Cambridge].<br />
<br />
More information about the hackathon location will be forthcoming.<br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Talks&diff=42594Hac Boston/Talks2011-10-27T01:54:47Z<p>Keegan: </p>
<hr />
<div>== Talks == <br />
<br />
{| class="wikitable"<br />
! Talk Name<br />
! Speaker<br />
|-<br />
| What Happened to Category Extras?<br />
| Edward Kmett<br />
|-<br />
| to be determined<br />
| Keegan McAllister<br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Projects&diff=42593Hac Boston/Projects2011-10-27T01:54:03Z<p>Keegan: /* Experience */</p>
<hr />
<div>== Sharing your code ==<br />
<br />
If you need a place to host a project so that others can help with it, we suggest <br />
[http://github.com github], but if you are using darcs [http://patch-tag.com/ patch-tag] is just dandy as well. <br />
<br />
You can also apply for an account on <br />
[http://community.haskell.org/admin/ the community server].<br />
<br />
== Projects ==<br />
<br />
If you have a project that you want to work on at the Hackathon, please describe it here.<br />
<br />
Since Hackathons are great for teamwork, consider joining one of the projects mentioned below. If you're interested in one of these projects, add your name to the list of hackers under that project.<br />
<br />
<!-- Copy this template<br />
=== Project name ===<br />
<br />
I am a project. Love me.<br />
<br />
* Hacker 1<br />
* Hacker 2<br />
--><br />
<br />
=== Trifecta ===<br />
<br />
[http://hackage.haskell.org/package/trifecta Trifecta] is a library for dealing with both parsing and the ancillary concerns that arise once you have a parser.<br />
<br />
* Edward Kmett<br />
<br />
== Experience ==<br />
<br />
Please list projects with which you are familiar. This way, people know whom to contact for more information or guidance on a particular project.<br />
<br />
{| class="wikitable"<br />
! Name<br />
! Projects<br />
|-<br />
| edwardk<br />
| [http://github.com/ekmett lots of projects], mtl, general libraries<br />
|-<br />
| ezyang<br />
| ghc<br />
|-<br />
| keegan<br />
| [https://github.com/kmcallister various], some GHC internals<br />
|}</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42592Hac Boston2011-10-27T01:18:10Z<p>Keegan: /* Map */</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Maps ==<br />
<br />
We have a Google map regarding [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation and places to stay], and another with [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c points of interest around Cambridge].<br />
<br />
More information about the hackathon location will be forthcoming.<br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42591Hac Boston2011-10-27T01:16:47Z<p>Keegan: /* Map */</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Map ==<br />
<br />
We have a Google map regarding [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03d5c010f8787f88 transportation and places to stay], and another with [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c points of interest around Cambridge].<br />
<br />
More information about the hackathon location will be forthcoming.<br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42590Hac Boston2011-10-27T00:31:07Z<p>Keegan: /* Getting to the Boston area */</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Map ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== By air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== By train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== By bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42589Hac Boston2011-10-27T00:03:03Z<p>Keegan: /* Dates and times */</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
The hackathon will run from January 20 to 22, 2012, at the following times:<br />
<br />
{|<br />
!Date<br />
!Day<br />
!Times<br />
|-<br />
|Jan 20<br />
|Friday<br />
|14:30 to 22:00<br />
|-<br />
|Jan 21<br />
|Saturday<br />
|09:00 to 22:00<br />
|-<br />
|Jan 22<br />
|Sunday<br />
|09:00 to 17:00<br />
|}<br />
<br />
There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive Thursday evening or Friday morning if it makes for easier travel. If enough people are around and interested, we can arrange pre-hackathon activities.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Map ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== Air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== Train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== Bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42588Hac Boston2011-10-26T23:55:36Z<p>Keegan: reorganize</p>
<hr />
<div>The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held '''January 20 to 22, 2012''' in '''Cambridge, Massachusetts''', at the [http://www.mit.edu/ Massachusetts Institute of Technology]. It is open to all &mdash; you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
__TOC__<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then you might want to visit<br />
<br />
* the [[/Projects|projects page]].<br />
<br />
* the IRC channel: #haskell-hacboston (freenode)<br />
<br />
* the mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Dates and times ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Map ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== Air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== Train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== Bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Organizers ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at +1 857 244 1001.<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42587Hac Boston2011-10-26T23:35:07Z<p>Keegan: remove redundant heading level</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Map ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== Air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== Train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== Bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Before you arrive ==<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42586Hac Boston2011-10-26T23:31:37Z<p>Keegan: change headings</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Map ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
== Getting to the Boston area ==<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
=== Air ===<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
=== Train ===<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
=== Bus ===<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
== Getting to MIT ==<br />
<br />
=== By human power ===<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
=== By public transit ===<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
=== By car ===<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
== Accommodation ==<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42585Hac Boston2011-10-26T23:30:23Z<p>Keegan: /* About */</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell [[Hackathon]] is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42584Hac Boston2011-10-26T23:18:08Z<p>Keegan: /* Air */</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a (infrequent) [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42583Hac Boston2011-10-26T23:14:44Z<p>Keegan: /* Location */</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hackathon&diff=42582Hackathon2011-10-26T23:12:12Z<p>Keegan: </p>
<hr />
<div>[[Image:Hac-axe-icon.png|Hac icon]]<br />
<br />
'''Hac: The Haskell Hackathon'''<br />
<br />
The Haskell developer community holds regular hackathons, to get<br />
together, collaborate, and work on key tools and infrastructure.<br />
<br />
* [[Hac_Boston|Boston / Cambridge, Jan 2012]]<br />
* [[HakkuTaikai|Tokyo, Sep 2011]]<br />
* [[CamHac|Cambridge, Aug 2011]]<br />
* [[HacPDX-II|Portland, Jul 2011]]<br />
* [[Hac φ|Philadelphia, Jul 2011]]<br />
* [[BayHac2011|SF Bay Area, Feb 2011]]<br />
* [[Ghent Functional Programming Group/BelHac|Ghent, Nov 2010]]<br />
* [[LtU-Kiev/Hackathon|Kiev, Oct 2010]]<br />
* [[AusHac2010|Australian Hackathon, Jul 2010]]<br />
* [[Hac φ|Philadelphia, May 2010]]<br />
* [[ZuriHac|Zurich, Mar 2010]]<br />
* [[HacPDX|Portland, OR, Sep 2009]]<br />
* [[Hac7|Edinburgh, Aug 2009]]<br />
* [[Hac φ|Philadelphia, Jul 2009]]<br />
* [[Hac5|Utrecht, Apr 2009]]<br />
* [[HaL3|Leipzig, Apr 2008]]<br />
* [[Hac 2008|Göteborg, Apr 2008]]<br />
* [[Hac 2007 II|Freiburg, Oct 2007]]<br />
* [[Hac 2007|Oxford, Jan 2007]]<br />
* [http://hackage.haskell.org/trac/ghc/wiki/Hackathon Portland, Sep 2006]<br />
<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42581Hac Boston2011-10-26T21:42:11Z<p>Keegan: /* Accommodation */</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]. Boston has several [http://www.hostelworld.com/search?search_keywords=Boston%2C+USA&country=USA&city=Boston hostels] as well.<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42580Hac Boston2011-10-26T20:45:24Z<p>Keegan: /* Location */ add new map</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/ms?ie=UTF&msa=0&msid=211126516447001200668.0004b03844f6a9021991c Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking. Talk to Keegan and we can put markers on the map for parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42579Hac Boston2011-10-26T19:11:19Z<p>Keegan: /* Train */ add BBY</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express. These trains also stop at Boston Back Bay (BBY). South Station is the better choice if taking transit to MIT, but Back Bay is closer for walking.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42578Hac Boston2011-10-26T18:55:51Z<p>Keegan: revert repeated vandalism by DylanLukes</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42569Hac Boston2011-10-26T04:03:09Z<p>Keegan: herp derp</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston/Attendees&diff=42565Hac Boston/Attendees2011-10-25T21:58:28Z<p>Keegan: </p>
<hr />
<div>This is a partial list of attendees for [[Hac Boston]]. Please refer to the [[Hac Boston|main page]] for more information.<br />
<br />
= Attendees =<br />
<br />
Feel free to list yourself here -- though this is ''not'' registration. To register, see [[Hac Boston/Register|this page]].<br />
<br />
{| class="wikitable"<br />
! Nickname<br />
! Real Name<br />
! Mobile #<br />
! Arriving<br />
! Departing<br />
! Accommodation<br />
|-<br />
| edwardk<br />
| Edward Kmett<br />
| (857)244-1001<br />
| -<br />
| -<br />
| lives in the area<br />
|-<br />
| dolio<br />
| Dan Doel<br />
| -<br />
| -<br />
| -<br />
| lives in the area<br />
|-<br />
| copumpkin<br />
| Dan Peebles<br />
| -<br />
| -<br />
| -<br />
| lives in the area<br />
|-<br />
| kmc<br />
| Keegan McAllister<br />
| -<br />
| -<br />
| -<br />
| lives in the area<br />
|}<br />
<br />
= Additional Comments =<br />
<br />
Please use this section to leave comments for other attendees, e.g. for organizing accommodation.</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42564Hac Boston2011-10-25T21:57:47Z<p>Keegan: derp</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42563Hac Boston2011-10-25T21:57:00Z<p>Keegan: fix spacing</p>
<hr />
<div>'''January 20-22, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 20-22, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 20-22, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
==== Keegan McAllister Style ====<br />
<br />
* Bring a multitool.<br />
* Exit security, make an immediate right. Enter the janitorial wing of the airport. Find the third from the right window. <br />
* Quickly remove the screws on the air duct immediately next to it. Crawl through to luggage handling.<br />
* Navigate the maze of conveyor belts and machinery. Do not fall.<br />
* Exit via the luggage pickup conveyor belt.<br />
* Exit via the nearest door. Take the Blue Line subway towards Bowdoin. Ride on top.<br />
* Do not get off at Government Center Station. Directly ransfer to the Green Line towards E - Heath Street by jumping from train to train.<br />
* Get off at Prudential Station. Do not let yourself be seen.<br />
* Climb a nearby fire escape. Parkour to 111 Huntington Ave. Copumpkin style, break in through 5 Napkin Burger, fight your way through security on the ground floor and take the service elevator right behind it. If it's not at the ground, climb the shaft. It's faster.<br />
* Alternatively, pose as catering from the nearby Cheesecake Factory. The receptionist is vulnerable to strawberry cheesecake.<br />
* Find Edward Kmett. Beat him up and take his keys.<br />
* Drive to MIT. Find directions on Google Maps.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42560Hac Boston2011-10-25T21:42:49Z<p>Keegan: more on transit</p>
<hr />
<div>'''January 21-23, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 21-23, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 21-23, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. From BOS you can take the [http://www.mbta.com/schedules_and_maps/subway/lines/?route=SILVER Silver Line SL1] bus to Boston South Station.<br />
<br />
[http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston South Station.<br />
<br />
==== Train ====<br />
<br />
[http://www.amtrak.com Amtrak] serves Boston South Station, station code BOS. Service from cities in the Northeast is available on both the Northeast Regional train and the marginally faster Acela Express.<br />
<br />
From certain points in Massachusetts and Rhode Island, you can take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus], [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star].<br />
<br />
<br />
=== Getting to MIT ===<br />
<br />
==== By human power ====<br />
<br />
Cambridge is a very walkable city. It is feasible to walk to MIT from many points in Cambridge, Boston, and Brookline. Cambridge is also very bikeable, but maybe not in January.<br />
<br />
==== By public transit ====<br />
<br />
MIT is close to [http://www.mbta.com/schedules_and_maps/subway/lines/stations/?stopId=12412 Kendall Station] on the Red Line subway. The Red Line connects to Boston South Station (and its rail and bus terminals) and the rest of the [http://www.mbta.com/schedules_and_maps/subway/ MBTA rapid transit network]. MIT is also served by [http://www.mbta.com/schedules_and_maps/bus/ MBTA buses]. Google Maps can plan rail and bus trips.<br />
<br />
TODO: Add map and walking directions from Kendall, once location is finalized.<br />
<br />
==== By car ====<br />
<br />
TODO: someone who drives to MIT should add information on routes and parking.<br />
<br />
==== Keegan McAllister Style ====<br />
<br />
* Bring a multitool.<br />
* Exit security, make an immediate right. Enter the janitorial wing of the airport. Find the third from the right window. <br />
* Quickly remove the screws on the air duct immediately next to it. Crawl through to luggage handling.<br />
* Navigate the maze of conveyor belts and machinery. Do not fall.<br />
* Exit via the luggage pickup conveyor belt.<br />
* Exit via the nearest door. Take the Blue Line subway towards Bowdoin. Ride on top.<br />
* Do not get off at Government Center Station. Directly ransfer to the Green Line towards E - Heath Street by jumping from train to train.<br />
* Get off at Prudential Station. Do not let yourself be seen.<br />
* Climb a nearby fire escape. Parkour to 111 Huntington Ave. Copumpkin style, break in through 5 Napkin Burger, fight your way through security on the ground floor and take the service elevator right behind it. If it's not at the ground, climb the shaft. It's faster.<br />
* Alternatively, pose as catering from the nearby Cheesecake Factory. The receptionist is vulnerable to strawberry cheesecake.<br />
* Find Edward Kmett. Beat him up and take his keys.<br />
* Drive to MIT. Find directions on Google Maps.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Hac_Boston&diff=42549Hac Boston2011-10-25T21:19:06Z<p>Keegan: edit transit (work in progress)</p>
<hr />
<div>'''January 21-23, 2012'''<br />
<br />
MIT, Cambridge, Massachusetts, USA<br />
<br />
== About ==<br />
<br />
The Haskell Hackathon is an international, grassroots collaborative coding festival with a simple focus: build and improve Haskell libraries, tools, and infrastructure.<br />
<br />
Hac Boston will be held January 21-23, 2012 at [http://www.mit.edu/ MIT] in [http://en.wikipedia.org/wiki/Cambridge Cambridge, MA]. It is open to all -- you do not have to be a Haskell guru to attend. All you need is a basic knowledge of Haskell, a willingness to learn, and a [[/Projects|project]] you're excited to help with (or a project of your own to work on).<br />
<br />
There will be lots of hacking, some talks, good food, and, of course, fun!<br />
<br />
* IRC channel: #haskell-hacboston (freenode)<br />
* Mailing list: [http://www.haskell.org/mailman/listinfo/hackathon hackathon@haskell.org]<br />
<br />
== Registration ==<br />
<br />
If you will be attending, please [[/Register|register]]. Registration is free, and open to everyone. If you like, you can also<br />
[[/Attendees|list yourself as an attendee]]. Then check out the [[/Projects|projects page]].<br />
<br />
== When ==<br />
<br />
January 21-23, 2012 from 2:30-10pm Friday, 9am-10pm Saturday, and 9am-5pm Sunday. There will probably be some talks Saturday afternoon.<br />
<br />
Although the hackathon won't officially kick off until 2:30pm on Friday, you are welcome to arrive the evening of Thursday the 20th or Friday morning if it makes for easier travel. If enough people are around and interested, some sort of activity could be arranged for Thursday evening and/or Friday morning.<br />
<br />
== Talks ==<br />
<br />
If you'd be interested in giving a short (15-20 minute) talk, put your name and the subject of your talk on the [[/Talks|talks page]]. There will be a projector and whiteboard available.<br />
<br />
== Sponsors ==<br />
<br />
Hac Boston 2012 is sponsored by [https://www.capitaliq.com/ Capital IQ], an active user of functional programming!<br />
<br />
== Location ==<br />
<br />
Check out the [http://maps.google.com/maps/place?q=mit&cid=15051186796996599868 Google map] for info on relevant locations. More information about the room will be forthcoming. <br />
<br />
=== Getting to the Boston area ===<br />
<br />
See also [http://wikitravel.org/en/Boston#Get_in Wikitravel].<br />
<br />
==== Air ====<br />
<br />
[http://www.massport.com/logan-airport/Pages/Default.aspx Logan International Airport] (BOS) is the closest major airport. [http://www.pvdairport.com/ T. F. Green Airport] (PVD) in Providence is another option, with a [http://mbta.com/schedules_and_maps/rail/lines/?route=PROVSTOU rail connection] to Boston.<br />
<br />
==== Train ====<br />
<br />
From most points, take [http://www.amtrak.com Amtrak] to South Station, station code (BOS). From certain points in Massachusetts and Rhode Island, take [http://mbta.com/schedules_and_maps/rail/ MBTA commuter rail], which arrives at South Station or North Station.<br />
<br />
[http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=117635619663929119581.00046ad73c83c72a23d67&ll=39.954783,-75.194485&spn=0.001667,0.002403&t=h&z=19 Google map].<br />
<br />
==== Bus ====<br />
<br />
Boston is served by many [http://busjunction.com/ bus companies]. From New York City, reasonable and cheap options include [http://us.megabus.com/ Megabus] [https://www.boltbus.com/ BoltBus], [http://www.fungwahbus.com/default.html Fung Wah], and [http://www.luckystarbus.com/ Lucky Star]<br />
<br />
<br />
==== Without a car ====<br />
<br />
* [http://www.mbta.org/ MBTA] operates the trains and busses in the Boston area. Fares are [http://mbta.com/fares_and_passes/subway/ listed on their website].<br />
You can also get a CharlieTicket (or CharlieCard) at most stops.<br />
<br />
* Walking is always an option. Cambridge is a very walkable city.<br />
<br />
==== From the airport ====<br />
<br />
* You can take the Silver Line to South Station and then take the T from South Station to Kendall Station.<br />
* Walking is probably not an option.<br />
<br />
=== Accommodation ===<br />
<br />
We're still actively investigating what kinds of bulk deals we can get on hotels in the area. <br />
<br />
There are a number of [http://web.mit.edu/visit/hotels.html nearby hotels suggested on the MIT web site]<br />
<br />
There may also be some local residents willing to accommodate a few attendees. See the [[/Attendees|attendees page]] for more info.<br />
<br />
== Preparations ==<br />
<br />
=== Before you arrive ===<br />
<br />
* Pick out a couple of projects to work on and familiarise yourself with them, or bring your own project(s) to work on. See the [[/Projects|projects page]] for a list of projects people plan to work on. If you plan to work on your own project, be sure to list it on the [[/Projects|projects page]] and set up a public repository if you don't already have one, so that other people can help hack on your project.<br />
* Install an up to date Haskell toolchain: at least ghc and cabal-install. If you don't already have these installed (or need to install from scratch on the laptop you're bringing), the easiest way is probably to install the [http://hackage.haskell.org/platform/ Haskell Platform].<br />
<br />
== Contact ==<br />
<br />
For any questions or emergencies, you can always call Edward Kmett at (857)244-1001.<br />
<br />
== Attendees ==<br />
<br />
See the [[/Attendees | Attendees]] page.<br />
<br />
== Organization ==<br />
<br />
The organizers of Hac Boston are:<br />
<br />
* Edward Kmett (ekmett)<br />
* Edward Yang (ezyang)<br />
<br />
[[Category:Community]]<br />
[[Category:Events]]<br />
[[Category:Hackathon]]</div>Keeganhttps://wiki.haskell.org/index.php?title=Introduction&diff=42446Introduction2011-10-15T20:43:55Z<p>Keegan: rewrite monster run-on sentence</p>
<hr />
<div>[[Category:Tutorials]] [[Category:Language]]<br />
Haskell is a computer programming language. In particular, it is a<br />
'' [[Polymorphism|polymorphically]] [[typing|statically typed]], [[Lazy evaluation|lazy]], [[functional programming|purely functional]] '' language,<br />
quite different from most other programming languages. <br />
The language is named for [[Haskell Brooks Curry]], whose work in mathematical logic serves as a foundation for<br />
functional languages. <br />
Haskell is based on the ''[[lambda calculus]]'', hence the lambda we use as a logo.<br />
<br />
<br />
==Why use Haskell?==<br />
Writing large software systems that<br />
work is difficult and expensive. Maintaining those systems is even<br />
more difficult and expensive. Functional programming languages, such<br />
as Haskell, can make it easier and cheaper. For example, a new user who<br />
wrote a small relational DBMS in Haskell had this to say:<br />
<blockquote><br />
WOW! I basically wrote this without testing just thinking about my<br />
program in terms of transformations between types. I wrote the<br />
test/example code and had almost no implementation errors in the code! The<br />
compiler/type-system is really really good at preventing you from<br />
making coding mistakes! I've never in my life had a block of code<br />
this big work on the first try. I am WAY impressed.<br />
</blockquote><br />
Even if you are not in a position to use Haskell in your programming projects, learning Haskell can make you a better programmer in any language. <br />
<blockquote><br />
I learned Haskell a couple of years ago, having previously programmed in<br />
Python and (many) other languages. Recently, I've been using Python for a<br />
project (the choice being determined by both technical and non-technical<br />
issues), and find my Python programming style is now heavily influenced (for the better, I hope ;-) by my Haskell programming experience.<br><br><br />
Graham Klyne<br />
</blockquote><br />
<br />
<br />
Haskell offers you:<br />
<br />
*Substantially increased programmer productivity (Ericsson measured an improvement factor of between 9 and 25 using Erlang, a functional programming language similar to Haskell, in one set of experiments on telephony software).<br />
*Shorter, clearer, and more maintainable code.<br />
*Fewer errors, higher reliability.<br />
*A smaller &quot;semantic gap&quot; between the programmer and the language.<br />
*Shorter lead times.<br />
<br />
Haskell is a wide-spectrum language, suitable for a variety of<br />
applications. It is particularly suitable for programs which need to<br />
be highly modifiable and maintainable.<br />
<br />
Much of a software product's life is spent in ''specification'',<br />
''design'' and ''maintenance'', and not in ''programming''.<br />
Functional languages are superb for writing specifications which can<br />
actually be executed (and hence tested and debugged). Such a<br />
specification then ''is'' the first prototype of the final<br />
program.<br />
<br />
Functional programs are also relatively easy to maintain, because the<br />
code is shorter, clearer, and the rigorous control of side effects<br />
eliminates a huge class of unforeseen interactions.<br />
<br />
==What is functional programming?==<br />
C, Java, Pascal, Ada, and so on, are all ''imperative''<br />
languages. They are &quot;imperative&quot; in the sense that they<br />
consist of a sequence of commands, which are executed strictly one<br />
after the other. Haskell is a ''functional'' language. A<br />
functional program is a single expression, which is executed by<br />
evaluating the expression. <br />
<br />
Anyone who has used a spreadsheet has experience of functional<br />
programming. In a spreadsheet, one specifies the value of each cell<br />
in terms of the values of other cells. The focus is on ''what'' is<br />
to be computed, not ''how'' it should be computed. For<br />
example:<br />
*we do not specify the order in which the cells should be calculated -&nbsp;instead we take it for granted that the spreadsheet will compute cells in an order which respects their dependencies.<br />
*we do not tell the spreadsheet how to allocate its memory - rather, we expect it to present us with an apparently infinite plane of cells, and to allocate memory only to those cells which are actually in use.<br />
*for the most part, we specify the value of a cell by an ''expression'' (whose parts can be evaluated in any order), rather than by a ''sequence of commands '' which computes its value.<br />
<br />
An interesting consequence of the spreadsheet's unspecified order<br />
of re-calculation is that the notion of assignment is not very useful.<br />
After all, if you don't know exactly when an assignment will<br />
happen, you can't make much use of it! This contrasts strongly<br />
with programs in conventional languages like C, which consist<br />
essentially of a carefully-specified sequence of assignments, or Java,<br />
in which the ordering of method calls is crucial to the meaning of a<br />
program. <br />
<br />
This focus on the high-level &quot;what&quot; rather than the<br />
low-level &quot;how&quot; is a distinguishing characteristic of<br />
functional programming languages.<br />
<br />
Another well-known nearly-functional language is the standard database<br />
query language SQL. An SQL query is an expression involving<br />
projections, selections, joins and so forth. The query says what<br />
relation should be computed, without saying how it should be computed.<br />
Indeed, the query can be evaluated in any convenient order. SQL<br />
implementations often perform extensive query optimization which<br />
(among other things) figures out the best order in which to evaluate<br />
the expression.<br />
<br />
==What's good about functional programming?==<br />
<br />
Spreadsheets and SQL are both fairly specialized languages. Functional<br />
programming languages take the same ideas and move them into the realm<br />
of general-purpose programming. To get an idea of what a functional<br />
program is like, and the expressiveness of functional languages, look at<br />
the following quicksort programs. They both sort a sequence of numbers<br />
into ascending order using a standard method called "quicksort". The<br />
first program is written in Haskell and the second in C. <br />
<br />
Whereas the C program describes the particular steps the machine must<br />
make to perform a sort -- with most code dealing with the low-level<br />
details of data manipulation -- the Haskell program encodes the sorting<br />
algorithm at a much higher level, with improved brevity and clarity as<br />
a result (at the cost of efficiency unless compiled by a very smart compiler):<br />
<br />
===Quicksort in Haskell===<br />
<br />
The first thing to know about Haskell's syntax is that parentheses are used for grouping, and not for function application. The application of a function <hask>f</hask> to an argument <hask>x</hask> is written <hask>f x</hask>, not <hask>f(x)</hask>. It can be written as <hask>(f x)</hask> to separate it from its surroundings.<br />
<br />
<haskell><br />
quicksort :: Ord a => [a] -> [a]<br />
quicksort [] = []<br />
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)<br />
where<br />
lesser = filter (< p) xs<br />
greater = filter (>= p) xs<br />
<br />
</haskell><br />
The parentheses indicate the grouping of operands on the right-hand side of equations. On the left they indicate ''patterns'' of a function's argument(s). The parentheses around <hask>(quicksort lesser)</hask> are unnecessary, because function application binds tighter than infix operators.<br />
<br />
Here <code>[]</code> stands for empty list, <code>[p]</code> for a singleton list holding one element <code>p</code>, <code>++</code> is a built-in list concatenation operator, and the two <code>filter</code> calls use two on-the-fly built predicates, first for getting all the elements of <code>xs</code> that are smaller than the pivot element <code>p</code>, and the other - all those greater than, or equal to it.<br />
<br />
This definition uses Haskell's ability to define functions as equations with pattern-matching clauses: here the first one, with <code>[]</code> pattern for an empty list on its left-hand side, and the second, with <code>(p:xs)</code> pattern on its left-hand side standing for non-empty list with the head element <code>p</code> (used as a pivot element), and the tail <code>xs</code> (which is read, by convention, as ''axes'', suggesting that it is a list of several ''xs'', viz. elements ''"x"'').<br />
<br />
The very first line above is the function's ''type signature'': it says that <code>quicksort</code> transforms a list of elements of some type <code>a</code> (usually read "alpha") into a list of the same type, for a type <code>a</code> that is an instance of typeclass <code>Ord</code> (which means that comparison operations are defined for it, so elements of type <code>a</code> can be compared with one another).<br />
<br />
===Quicksort in C===<br />
<br />
True quicksort in C sorts in-place:<br />
<pre><br />
// To sort array a[] of size n: qsort(a,0,n-1)<br />
<br />
void qsort(int a[], int lo, int hi) <br />
{<br />
int h, l, p, t;<br />
<br />
if (lo &lt; hi) {<br />
l = lo;<br />
h = hi;<br />
p = a[hi];<br />
<br />
do {<br />
while ((l &lt; h) &amp;&amp; (a[l] &lt;= p)) <br />
l = l+1;<br />
while ((h &gt; l) &amp;&amp; (a[h] &gt;= p))<br />
h = h-1;<br />
if (l &lt; h) {<br />
t = a[l];<br />
a[l] = a[h];<br />
a[h] = t;<br />
}<br />
} while (l &lt; h);<br />
<br />
a[hi] = a[l];<br />
a[l] = p;<br />
<br />
qsort( a, lo, l-1 );<br />
qsort( a, l+1, hi );<br />
}<br />
}<br />
</pre><br />
<br />
A [[/Direct Translation | semi-direct translation]] of the C code is here.<br />
<br />
Let's examine some of the benefits of Haskell and functional programming.<br />
A more detailed case for functional programming can be found in <br />
<br />
<BLOCKQUOTE><br />
[http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf '''Why Functional Programming Matters'''] by [http://www.cse.chalmers.se/~rjmh/ John Hughes], The Computer<br />
Journal, Vol. 32, No. 2, 1989, pp. 98 - 107. Also in: David A. Turner<br />
(ed.): Research Topics in Functional Programming, Addison-Wesley,<br />
1990, pp. 17 - 42. <br />
</BLOCKQUOTE><br />
A slightly less formal essay inspired by the paper above can be found in<br />
<BLOCKQUOTE><br />
[[Why Haskell matters |'''Why Haskell Matters''']] originally by [mailto:sylvan@dtek.chalmers.se Sebastian Sylvan]<br />
</BLOCKQUOTE><br />
<br />
===Ease of understanding===<br />
Functional programs are often easier to '''understand''': it is usually possible to get their meaning at a glance. The same certainly cannot be said of the C program. It takes quite a while to understand, and even when you do understand it, it is extremely easy to make a small slip and end up with an incorrect program. <br />
<br />
Here is a detailed explanation of the Haskell quicksort:<br />
<br />
<haskell><br />
quicksort [] = []<br />
</haskell><br />
The first clause reads: "The result of sorting an empty list (<tt>[]</tt>) is just an empty list (<tt>[]</tt>)". <br />
<br />
<haskell><br />
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)<br />
where<br />
lesser = filter (< p) xs<br />
greater = filter (>= p) xs<br />
</haskell><br />
The second clause reads: "The result of sorting a non-empty list whose first element will be henceforth referred to as <tt>p</tt> and<br />
the rest of which will be referred to as <tt>xs</tt>, is a result of concatenating three sublists: first the result of sorting the elements of <tt>xs</tt> that are less than <tt>p</tt>, then <tt>p</tt> itself, and then the result of sorting the elements of <tt>xs</tt> that are greater than or equal to <tt>p</tt>."<br />
<br />
===Brevity===<br />
Functional programs tend to be much more '''concise''', shorter by a factor of two to ten usually, than their imperative counterparts. <br />
<br />
The above could be written even more concisely with the help of [[list comprehension]]s:<br />
<haskell><br />
qsort (p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]<br />
</haskell><br />
<br />
The first sub-expression means, for <code>x</code> drawn from <code>xs</code> in order, such that <code>x < p</code>, collect <code>x</code>s in a list and call the <code>qsort</code> function with it, recursively. Similarly for the last one.<br />
<br />
===No core dumps===<br />
Most functional languages, and Haskell in particular, are '''strongly<br />
typed''', eliminating a huge class of easy-to-make errors at compile<br />
time. In particular, strong typing means '''no core dumps'''!<br />
There is simply no possibility of treating an integer as a pointer, or<br />
following a null pointer.<br />
<br />
===Code re-use===<br />
Of course, strong typing is available in many imperative languages, such as Ada or Pascal. However, Haskell's type system is much less restrictive than, say, Pascal's, because it uses '''[[polymorphism]]'''.<br />
<br />
For example, the qsort program given in Figure 1 will not only sort lists of integers, but also lists of floating point numbers, lists of characters, lists of lists; indeed, it will sort lists of ''anything'' for which it is meaningful to have "less-than" and "greater-than" operations. In contrast, the C version can only sort an array of integers, and nothing else.<br />
<br />
Polymorphism enhances re-usability.<br />
<br />
===Strong glue===<br />
"Non-strict" functional languages, such as Haskell, have another powerful feature: they<br />
only evaluate as much of the program as is required to get the answer<br />
- this is called [[Haskell/Lazy evaluation |'''lazy evaluation''']]. This feature is rather<br />
like Unix pipes. For example, the Unix command<br />
<pre><br />
grep printf Foo.c | wc<br />
</pre><br />
counts the number of lines in the file <tt> Foo.c </tt>that include the<br />
string <tt>printf</tt>.<br />
The command <br />
<pre><br />
grep printf Foo.c<br />
</pre><br />
produces all lines which contain the string &quot;<tt>printf</tt>&quot;,<br />
while the &quot;<tt>wc</tt>&quot; command counts them. The pipe,<br />
written &quot;<tt>|</tt>&quot;, takes the output from the first command<br />
and delivers it to the second. The two commands execute together, so<br />
that the output of the first is consumed more-or-less immediately by<br />
the second. In this way, no large intermediate files need be<br />
produced. You can think of <tt>wc</tt> &quot;demanding&quot;<br />
lines from the <tt>grep</tt>.<br />
<br />
If the second command only needs some of the output of the first, then<br />
execution of the first command might never need to be completed. For<br />
example,<br />
<br />
<pre><br />
grep printf Foo.c | head 5<br />
</pre><br />
just prints the first 5 lines which contain &quot;<tt>printf</tt>&quot;.<br />
There is no need to modify the <tt>grep</tt> command to take account of<br />
the fact that its execution might be abandoned.<br />
<br />
[[Lazy vs. non-strict |Non-strict]] languages provide exactly this kind of demand-driven<br />
evaluation. Data structures are evaluated just enough to deliver the<br />
answer, and parts of them may not be evaluated at all. As in the case<br />
of Unix commands, this provides powerful &quot;glue&quot; with which<br />
to compose existing programs together. What this means is that it is<br />
possible to '''re-use programs''', or pieces of programs, much more<br />
often than can be done in an imperative setting. [[Haskell/Lazy evaluation |Lazy evaluation]] allows us to write more '''[[modular programs]]'''.<br />
<br />
===Powerful abstractions===<br />
In general, functional languages offer powerful new ways to<br />
encapsulate '''abstractions'''. An abstraction allows you to define<br />
an object whose internal workings are hidden; a C procedure, for<br />
example, is an abstraction. Abstractions are ''the'' key to<br />
building modular, maintainable programs, so much so that a good<br />
question to ask of any new language is "what mechanisms for<br />
abstraction does it provide?". <br />
<br />
One powerful abstraction mechanism available in functional languages<br />
is the '''[[higher order function]]'''. In Haskell a function is a<br />
first-class citizen: it can freely be passed to other functions,<br />
returned as the result of a function, stored in a data structure, and<br />
so on. It turns out that the judicious use of higher order functions<br />
can substantially improve the structure and modularity of many<br />
programs.<br />
<br />
===Built-in memory management===<br />
Very many sophisticated programs need to allocate dynamic memory from a heap. In C this is done with a call to <tt> malloc</tt>, followed by code to initialize the store just allocated. The programmer is responsible for returning the store to the free pool when it isn't needed any more, a notorious source of "dangling-pointer" errors. To make matters worse, <tt>malloc</tt> is fairly expensive performance-wise, so programmers often <tt>malloc</tt> a single large chunk of store, and then allocate "by hand" out of this.<br />
<br />
Every functional language relieves the programmer of this storage management burden. Store is allocated and initialized implicitly, and recovered automatically by the garbage collector. The technology of storage allocation and garbage collection is now well developed, and the performance costs are rather slight.<br />
<br />
==When C is better==<br />
It isn't all roses, of course. The C quicksort uses an extremely<br />
ingenious technique, invented by Hoare, whereby it sorts the array<br />
''in place''; that is, without using any extra storage. As a<br />
result, it runs quickly, and in a small amount of memory. In<br />
contrast, the Haskell program allocates quite a lot of extra memory<br />
behind the scenes, and runs rather slower than the C program. <br />
<br />
In effect, the C quicksort does some very ingenious storage<br />
management, trading this algorithmic complexity for a reduction in<br />
run-time storage management costs.<br />
<br />
In applications where [[performance]] is required at any cost, or when the<br />
goal is detailed tuning of a low-level algorithm, an imperative<br />
language like C would probably be a better choice than Haskell,<br />
exactly because it provides more intimate control over the exact way<br />
in which the computation is carried out - that is, until sufficiently smart compiler appears that is able to derive the C equivalent from the Haskell one-liner, all by itself.<br />
<br />
===Functional vs imperative===<br />
But few programs require performance at any cost! After all, we all<br />
stopped writing assembly-language programs, except perhaps for key<br />
inner loops, long ago. The benefits of having a more supportive<br />
programming model (an arbitrary number of named, local variables<br />
instead of a fixed number of registers, for example) far outweigh the<br />
modest run-time costs.<br />
<br />
Similarly, we willingly accept the costs of a virtual memory paging<br />
system, in exchange for the more supportive programming model of an<br />
infinite virtual address space. The days of explicit memory overlays<br />
are over.<br />
<br />
Functional languages take another large step towards a higher-level<br />
programing model. Programs are easier to design, write and maintain,<br />
but the language offers the programmer less control over the machine.<br />
For most programs the result is perfectly acceptable.<br />
<br />
==What is Haskell?==<br />
Haskell is a modern, standard, non-strict, purely-functional<br />
programming language. It provides all the features sketched above,<br />
including polymorphic typing, lazy evaluation and higher-order<br />
functions. It also has an innovative type system which supports a<br />
systematic form of overloading and a module system.<br />
<br />
It is specifically designed to handle a wide range of applications,<br />
from numerical through to symbolic. To this end, Haskell has an<br />
expressive syntax, and a rich variety of built-in data types,<br />
including arbitrary-precision integers and rationals, as well as the<br />
more conventional integer, floating-point and boolean types.<br />
<br />
There are a number of [[compilers and interpreters]] available. All are<br />
free. First-time users may want to start with [[Hugs]], a small, portable Haskell interpreter. <br />
<br />
See also [[History of Haskell|the History of Haskell]]<br />
<br />
==Does anyone use functional programming?==<br />
Functional programming languages are used in substantial applications.<br />
For example:<br />
* Software AG, a major German software company, market an expert system (Natural Expert) which is programmed in a functional language. Their users find it easy to develop their applications in this language, through which they gain access to an underlying database system. It all runs on an IBM mainframe.<br />
*Ericsson have developed a new functional language, Erlang, to use in their future telephony applications. They have already written 130k-line Erlang applications, and find them very much shorter and faster to develop.<br />
*Amoco ran an experiment in which they re-coded in Miranda, a lazy functional language, a substantial fraction of their main oil-reservoir simulation code, a critical application. The resulting program was vastly shorter, and its production revealed a number of errors in the existing software. Amoco subsequently transcribed the functional program into C++ with encouraging results.<br />
*A researcher at the MITRE corporation is using Haskell to prototype his digital signal-processing applications.<br />
*Researchers at Durham University used Miranda, and later Haskell, in a seven-year project to build LOLITA, a 30,000-line program for natural-language understanding.<br />
*Query is the query language of the O2 object-oriented database system. O2Query is probably the most sophisticated commercially-available object-oriented database query language and it is a functional language.<br />
*ICAD Inc market a CAD system for mechanical and aeronautical engineers. The language in which the engineers describe their design is functional, and it uses lazy evaluation extensively to avoid recomputing parts of the design which are not currently visible on the screen. This results in substantial performance improvements.<br />
*An incestuous example: the Glasgow Haskell compiler is written in Haskell: a 100,000-line application.<br />
*[http://pugscode.org Pugs], the leading perl6 implementation is written in Haskell<br />
*As is [http://darcs.net Darcs], a cutting edge distributed revision control system<br />
<br />
Some other examples of [[Haskell in practice]].<br />
<br />
Clifford Beshers, of [http://www.linspire.com/ Linspire Inc]., describes their experience with Haskell, and functional programming:<br />
<br />
<blockquote><br />
Linspire, Inc. has used functional programming since its inception in<br />
2001, beginning with extensive use of O'Caml, with a steady shift to<br />
Haskell as its implementations and libraries have matured. Hardware<br />
detection, software packaging and CGI web page generation are all areas<br />
where we have used functional programming extensively.<br />
</blockquote><br />
<br />
<blockquote><br />
Haskell's feature set lets us replace much of our use of little<br />
languages (e.g., bash or awk) and two-level languages (C or C++ bound to<br />
an interpreted language), allowing for faster development, better code<br />
sharing and ultimately faster implementations. Above all, we value<br />
static type checking for minimizing runtime errors in applications that<br />
run in unknown environments and for wrapping legacy programs in strongly<br />
typed functions to ensure that we pass valid arguments.<br />
</blockquote><br />
<br />
==Other frequently-asked questions==<br />
<br />
There is also a [[FAQ|larger FAQ]] in progress.<br />
<br />
===''Is functional programming hard to learn?''===<br />
<blockquote><br />
Functional programming does require a change in perspective, which<br />
some programmers find hard. But Ericsson's experience in training<br />
programmers in Erlang is that most find the transition easy -<br />
provided they take the training need seriously rather than assuming<br />
that they can "pick it up on the day".<br />
</blockquote><br />
===''Aren't functional programs very slow?''===<br />
<blockquote>They used to be, perhaps 20 years ago. But the compilers<br />
have long since caught up. Haskell programs run fast for all but the<br />
most performance-demanding applications. At the time of writing, Haskell<br />
compiled via GHC is in 2nd place (behind C) in the <br />
[http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all Great Language Shootout],<br />
with other functional languages also ranked highly.<br />
</blockquote><br />
<br />
===''I already have a large application in C or C++.''===<br />
Also worded as: ''Can I benefit from functional programming without rewriting my whole system?''<br />
<blockquote><br />
<br />
Haskell has been successfully integrated into existing applications in<br />
a number of ways. <br />
[http://www.haskell.org/hdirect/ HaskellDirect] is<br />
an IDL (Interface Description Language) based tool that allows Haskell<br />
programs to work with software components. Low level C/C++ interfaces<br />
can be generated with<br />
[http://www.haskell.org/greencard Green Card] or <br />
[http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ C->Haskell], allowing <br />
tight integration between Haskell and C. These tools have been used<br />
to build a large number of successful, mixed language systems.<br />
</blockquote><br />
<br />
==='' What libraries does Haskell support?''===<br />
<blockquote><br />
Many software libraries have been developed for Haskell. See the<br />
[[Libraries and tools| list of Haskell libraries]] for a list of much of<br />
what is available.<br />
<br />
</blockquote><br />
<br />
==='' What other software tools for Haskell are there? ''===<br />
<blockquote><br />
Glasgow Haskell comes with a profiler which allows you to find which<br />
parts of your program are consuming most time and space. Chalmers<br />
Haskell has a space-profiling tool, and a quasi-parallel simulator<br />
which allows you to experiment with running your program in<br />
parallel. Hugs also has some similar tools. For a complete list, check<br />
the [[Libraries and tools|tools page]].<br />
</blockquote><br />
<br />
===''How can I ask for help?''===<br />
There is a large community of haskell users willing to help. They can be contacted on maillists, IRC, or StackOverflow<br />
<br />
<br />
===''Can I get a support contract or a help-line?''===<br />
<blockquote><br />
It used to be the case that if you wanted help, you had to persuade a<br />
Haskell research group that your problem was interesting enough or<br />
important enough that they should spend time helping you for free.<br />
<br><br />
Whilst that is still an option, there is now a<br />
[[Consultants|directory of Haskell Consultants]] who provide:<br />
<br />
*Support for compilers, tools and libraries.<br />
*Help with improving code quality (time, space, robustness, maintainability, etc.) using code reviews and tools.<br />
*Help with using libraries, tools and advanced Haskell features such as type system extensions, exception handling, the foreign function interface, test harnesses, and concurrency.<br />
*Library and application development.<br />
*Staff training.<br />
<br />
These companies and individuals tend to work closely with those<br />
developing Haskell (indeed, they have usually made major<br />
contributions to Haskell themselves). <br />
<br />
</blockquote><br />
===''How can I learn Haskell?''===<br />
<blockquote><br />
The easiest way to learn Haskell is with a [[Books|textbook]]. There are a lot of [[Tutorials|online tutorials]], but you'll have a much easier time to learn the basics from a book. After all, Haskell is very different from traditional mainstream languages, it's like learning programming anew.<br />
</blockquote><br />
<br />
===''Comparisons to other languages''===<br />
<blockquote><br />
[[Comparison of functional programming languages | Click to see a table comparing features of Haskell to similar languages]]<br />
</blockquote><br />
<br />
''Based on a paper by Simon Peyton Jones.''</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41936FAQ2011-09-07T04:41:09Z<p>Keegan: /* Concurrency and parallelism */</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What should I know before trying to understand monads? ==<br />
<br />
Let's look at part of the definition of <hask>Monad</hask>:<br /><br /><br />
<br />
<haskell><br />
class Monad m where<br />
(>>=) :: m a -> (a -> m b) -> m b<br />
</haskell><br />
<br />
This uses a lot of features:<br />
<br />
* first-class functions: the second argument to <hask>(>>=)</hask> is a function<br />
<br />
* type constructors (here <hask>m</hask>)<br />
<br />
* type class polymorphism<br />
<br />
* type class polymorphism ''over'' type constructors (which few other languages have)<br />
<br />
* parametric (not type class) polymorphism, over <hask>a</hask> and <hask>b</hask><br />
<br />
Each of these features is more fundamental than the specific idea of monads. If you understand each feature, then <hask>Monad</hask> is a small example of how they fit together. <hask>Functor</hask> is a slightly simpler example, and you can start there instead (see [[Typeclassopedia]]).<br />
<br />
== Aren't monads just a hack for handling impure things in a pure language? ==<br />
<br />
No. This is wrong in several ways.<br />
<br />
First, '''<hask>Monad</hask> isn't special.''' <hask>Monad</hask> is an ordinary Haskell type class. You can define it yourself in a few lines of pure Haskell code, so it's definitely not adding magical new capabilities to the language. Besides that, <hask>Monad</hask> is an API, not an implementation.<br /><br /><br />
<br />
(The <hask>do</hask> syntax ''is'' special, but it's only [[syntactic sugar]]. There's a straightforward translation to ordinary function calls, lambdas, etc.)<br /><br /><br />
<br />
Second, '''most monads have nothing to do with effects or "impurity".''' The <hask>Monad</hask> API is implemented by many different type constructors, including <hask>Maybe</hask> and <hask>[]</hask>. Lists and <hask>Maybe</hask> values are straightforward, familiar data values. There's nothing "impure" about them.<br /><br /><br />
<br />
Third, '''<hask>IO</hask> is not an exception to purity.''' IO actions are pure, first-class values like any other. You can create, store, and evaluate them without causing side effects. IO actions are just ''descriptions'' of IO which ''could'' be performed.<br /><br />
<br />
In short, Haskell programs are pure-functional programs which compute imperative programs.<br />
<br />
It's true that <hask>IO</hask> implements the <hask>Monad</hask> API, but that's not fundamental. You could instead use non-overloaded functions like<br /><br /><br />
<br />
<haskell><br />
returnIO :: a -> IO a<br />
bindIO :: IO a -> (a -> IO b) -> IO b<br />
</haskell><br />
<br />
<br />to glue together IO actions, and it would all work out basically the same. We use the generic <hask>Monad</hask> API for <hask>IO</hask> not because we have to, but because it lets us reuse convenient syntax and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html libraries]. Indeed, you can [[Introduction to IO|introduce <tt>IO</tt>]] without mentioning <hask>Monad</hask> at all.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
= Concurrency and parallelism =<br />
<br />
See also notes on [[parallel]] and [[Concurrency|concurrent]] programming.<br />
<br />
== How can I do X without resorting to threads? ==<br />
<br />
That's usually the wrong attitude. Threads are useful for solving problems. The attitude comes from other languages where some combination of the following holds:<br />
<br />
* Per-thread overhead consumes a lot of memory or CPU<br />
<br />
* Thread APIs are cumbersome, sometimes due to lacking first-class functions or IO actions<br />
<br />
* The thread implementation is fundamentally broken, e.g. a global interpreter lock<br />
<br />
* Threads break easily because programs constantly mutate implicitly-shared state<br />
<br />
None of these is true in GHC Haskell. Threads have disadvantages and are not always the right tool. But avoiding them at all costs is counterproductive.<br />
<br />
== What's the difference between concurrency and parallelism? ==<br />
<br />
Briefly: concurrency describes semantics; parallelism describes an implementation property.<br />
<br />
Concurrent programs are written with explicit threads of control. Concurrent semantics fit naturally with certain real-world problems, like a network server talking to many simultaneous clients. This is still a nice model for writing a network server, even if you only intend to run it on one CPU core — concurrency without parallelism.<br />
<br />
Parallel programs are those which run on multiple CPU cores simultaneously, regardless of how they were implemented.<br />
<br />
Concurrency is a popular way to obtain parallel performance, but converting a pure computation to use concurrent semantics is difficult and error-prone. GHC Haskell provides "[http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html semi-implicit parallelism]" as an alternative. Adding these "annotations" to a program cannot change its behavior.<br />
<br />
There's a longer discussion on the [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ GHC blog].<br />
<br />
== How do <hask>par</hask>, <hask>pseq</hask>, and <hask>seq</hask> relate? ==<br />
<br />
The expression <hask>par x y</hask> is semantically equivalent to <hask>y</hask>, but suggests to the runtime system that evaluating <hask>x</hask> in parallel might be a good idea. Usually <hask>x</hask> would be a variable referring to a thunk (unevaluated expression) that will later be needed.<br /><br /><br />
<br />
Now consider <hask>par x (x+y)</hask>. Evaluating this expression suggests evaluating <hask>x</hask> in parallel. But before the runtime system can act on that suggestion, we evaluate <hask>(x+y)</hask>, which will evaluate both <hask>x</hask> and <hask>y</hask> in sequence. It would be better to work on <hask>y</hask> for a while, and only demand <hask>x</hask> later, after perhaps some parallel work has occurred. We can use <hask>pseq</hask> to force this evaluation order, as in <hask>par x (pseq y (x+y))</hask>.<br /><br /><br />
<br />
The [http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html Strategies] module provides a nicer interface to these <hask>par</hask> / <hask>pseq</hask> tricks.<br />
<br />
<p><hask>seq</hask> is similar to <hask>pseq</hask> but provides a weaker guarantee. [http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg10973.html The details] are subtle; suffice to say that if you're controlling evaluation order, you want <hask>pseq</hask>.</p><br />
<br />
== How do I do event-based IO in GHC Haskell? Should I call <tt>select</tt>, <tt>epoll</tt>, etc? ==<br />
<br />
No; just do blocking IO from multiple threads, and GHC's runtime system will make these calls for you. GHC Haskell gives you the performance benefits of event-based IO without making you turn your code inside-out.<br />
<br />
Threads in GHC are lightweight — both in performance and in the mental effort of using them. You can handle [http://blog.johantibell.com/2010/09/final-version-of-our-ghc-io-manager.html ten thousand concurrent requests] at high throughput with a naive "one thread per client" model.<br />
<br />
== What's the difference between <hask>forkIO</hask> and <hask>forkOS</hask>? ==<br />
<br />
It only matters if you're calling into a C library that cares about thread-local state. In that case, <hask>forkOS</hask> guarantees that the C library will see the same OS thread each time. Any difference beyond that is an implementation detail and subject to change.<br />
<br />
== How can I wait for a thread to finish and produce a result? ==<br />
<br />
There's a few libraries for this on Hackage, like [http://hackage.haskell.org/package/async <tt>async</tt>], [http://hackage.haskell.org/package/spawn <tt>spawn</tt>], and [http://hackage.haskell.org/package/threads <tt>threads</tt>].<br />
<br />
It's not hard to implement this yourself using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html <tt>MVar</tt>], though it's harder to get the exception handling right.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41670FAQ2011-08-17T13:31:47Z<p>Keegan: more on monads and IO /* The M-word */</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What should I know before trying to understand monads? ==<br />
<br />
Let's look at part of the definition of <hask>Monad</hask>:<br /><br /><br />
<br />
<haskell><br />
class Monad m where<br />
(>>=) :: m a -> (a -> m b) -> m b<br />
</haskell><br />
<br />
This uses a lot of features:<br />
<br />
* first-class functions: the second argument to <hask>(>>=)</hask> is a function<br />
<br />
* type constructors (here <hask>m</hask>)<br />
<br />
* type class polymorphism<br />
<br />
* type class polymorphism ''over'' type constructors (which few other languages have)<br />
<br />
* parametric (not type class) polymorphism, over <hask>a</hask> and <hask>b</hask><br />
<br />
Each of these features is more fundamental than the specific idea of monads. If you understand each feature, then <hask>Monad</hask> is a small example of how they fit together. <hask>Functor</hask> is a slightly simpler example, and you can start there instead (see [[Typeclassopedia]]).<br />
<br />
== Aren't monads just a hack for handling impure things in a pure language? ==<br />
<br />
No. This is wrong in several ways.<br />
<br />
First, '''<hask>Monad</hask> isn't special.''' <hask>Monad</hask> is an ordinary Haskell type class. You can define it yourself in a few lines of pure Haskell code, so it's definitely not adding magical new capabilities to the language. Besides that, <hask>Monad</hask> is an API, not an implementation.<br /><br /><br />
<br />
(The <hask>do</hask> syntax ''is'' special, but it's only [[syntactic sugar]]. There's a straightforward translation to ordinary function calls, lambdas, etc.)<br /><br /><br />
<br />
Second, '''most monads have nothing to do with effects or "impurity".''' The <hask>Monad</hask> API is implemented by many different type constructors, including <hask>Maybe</hask> and <hask>[]</hask>. Lists and <hask>Maybe</hask> values are straightforward, familiar data values. There's nothing "impure" about them.<br /><br /><br />
<br />
Third, '''<hask>IO</hask> is not an exception to purity.''' IO actions are pure, first-class values like any other. You can create, store, and evaluate them without causing side effects. IO actions are just ''descriptions'' of IO which ''could'' be performed.<br /><br />
<br />
In short, Haskell programs are pure-functional programs which compute imperative programs.<br />
<br />
It's true that <hask>IO</hask> implements the <hask>Monad</hask> API, but that's not fundamental. You could instead use non-overloaded functions like<br /><br /><br />
<br />
<haskell><br />
returnIO :: a -> IO a<br />
bindIO :: IO a -> (a -> IO b) -> IO b<br />
</haskell><br />
<br />
<br />to glue together IO actions, and it would all work out basically the same. We use the generic <hask>Monad</hask> API for <hask>IO</hask> not because we have to, but because it lets us reuse convenient syntax and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html libraries]. Indeed, you can [[Introduction to IO|introduce <tt>IO</tt>]] without mentioning <hask>Monad</hask> at all.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
= Concurrency and parallelism =<br />
<br />
See also notes on [[parallel]] and [[Concurrency|concurrent]] programming.<br />
<br />
== What's the difference between concurrency and parallelism? ==<br />
<br />
Briefly: concurrency describes semantics; parallelism describes an implementation property.<br />
<br />
Concurrent programs are written with explicit threads of control. Concurrent semantics fit naturally with certain real-world problems, like a network server talking to many simultaneous clients. This is still a nice model for writing a network server, even if you only intend to run it on one CPU core — concurrency without parallelism.<br />
<br />
Parallel programs are those which run on multiple CPU cores simultaneously, regardless of how they were implemented.<br />
<br />
Concurrency is a popular way to obtain parallel performance, but converting a pure computation to use concurrent semantics is difficult and error-prone. GHC Haskell provides "[http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html semi-implicit parallelism]" as an alternative. Adding these "annotations" to a program cannot change its behavior.<br />
<br />
There's a longer discussion on the [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ GHC blog].<br />
<br />
== How do <hask>par</hask>, <hask>pseq</hask>, and <hask>seq</hask> relate? ==<br />
<br />
The expression <hask>par x y</hask> is semantically equivalent to <hask>y</hask>, but suggests to the runtime system that evaluating <hask>x</hask> in parallel might be a good idea. Usually <hask>x</hask> would be a variable referring to a thunk (unevaluated expression) that will later be needed.<br /><br /><br />
<br />
Now consider <hask>par x (x+y)</hask>. Evaluating this expression suggests evaluating <hask>x</hask> in parallel. But before the runtime system can act on that suggestion, we evaluate <hask>(x+y)</hask>, which will evaluate both <hask>x</hask> and <hask>y</hask> in sequence. It would be better to work on <hask>y</hask> for a while, and only demand <hask>x</hask> later, after perhaps some parallel work has occurred. We can use <hask>pseq</hask> to force this evaluation order, as in <hask>par x (pseq y (x+y))</hask>.<br /><br /><br />
<br />
The [http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html Strategies] module provides a nicer interface to these <hask>par</hask> / <hask>pseq</hask> tricks.<br />
<br />
<p><hask>seq</hask> is similar to <hask>pseq</hask> but provides a weaker guarantee. [http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg10973.html The details] are subtle; suffice to say that if you're controlling evaluation order, you want <hask>pseq</hask>.</p><br />
<br />
== How do I do event-based IO in GHC Haskell? Should I call <tt>select</tt>, <tt>epoll</tt>, etc? ==<br />
<br />
No; just do blocking IO from multiple threads, and GHC's runtime system will make these calls for you. GHC Haskell gives you the performance benefits of event-based IO without making you turn your code inside-out.<br />
<br />
Threads in GHC are lightweight — both in performance and in the mental effort of using them. You can handle [http://blog.johantibell.com/2010/09/final-version-of-our-ghc-io-manager.html ten thousand concurrent requests] at high throughput with a naive "one thread per client" model.<br />
<br />
== What's the difference between <hask>forkIO</hask> and <hask>forkOS</hask>? ==<br />
<br />
It only matters if you're calling into a C library that cares about thread-local state. In that case, <hask>forkOS</hask> guarantees that the C library will see the same OS thread each time. Any difference beyond that is an implementation detail and subject to change.<br />
<br />
== How can I wait for a thread to finish and produce a result? ==<br />
<br />
There's a few libraries for this on Hackage, like [http://hackage.haskell.org/package/async <tt>async</tt>], [http://hackage.haskell.org/package/spawn <tt>spawn</tt>], and [http://hackage.haskell.org/package/threads <tt>threads</tt>].<br />
<br />
It's not hard to implement this yourself using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html <tt>MVar</tt>], though it's harder to get the exception handling right.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41648FAQ2011-08-16T12:27:00Z<p>Keegan: more concurrency</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
= Concurrency and parallelism =<br />
<br />
See also notes on [[parallel]] and [[Concurrency|concurrent]] programming.<br />
<br />
== What's the difference between concurrency and parallelism? ==<br />
<br />
Briefly: concurrency describes semantics; parallelism describes an implementation property.<br />
<br />
Concurrent programs are written with explicit threads of control. Concurrent semantics fit naturally with certain real-world problems, like a network server talking to many simultaneous clients. This is still a nice model for writing a network server, even if you only intend to run it on one CPU core — concurrency without parallelism.<br />
<br />
Parallel programs are those which run on multiple CPU cores simultaneously, regardless of how they were implemented.<br />
<br />
Concurrency is a popular way to obtain parallel performance, but converting a pure computation to use concurrent semantics is difficult and error-prone. GHC Haskell provides "[http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html semi-implicit parallelism]" as an alternative. Adding these "annotations" to a program cannot change its behavior.<br />
<br />
There's a longer discussion on the [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ GHC blog].<br />
<br />
== How do <hask>par</hask>, <hask>pseq</hask>, and <hask>seq</hask> relate? ==<br />
<br />
The expression <hask>par x y</hask> is semantically equivalent to <hask>y</hask>, but suggests to the runtime system that evaluating <hask>x</hask> in parallel might be a good idea. Usually <hask>x</hask> would be a variable referring to a thunk (unevaluated expression) that will later be needed.<br /><br /><br />
<br />
Now consider <hask>par x (x+y)</hask>. Evaluating this expression suggests evaluating <hask>x</hask> in parallel. But before the runtime system can act on that suggestion, we evaluate <hask>(x+y)</hask>, which will evaluate both <hask>x</hask> and <hask>y</hask> in sequence. It would be better to work on <hask>y</hask> for a while, and only demand <hask>x</hask> later, after perhaps some parallel work has occurred. We can use <hask>pseq</hask> to force this evaluation order, as in <hask>par x (pseq y (x+y))</hask>.<br /><br /><br />
<br />
The [http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html Strategies] module provides a nicer interface to these <hask>par</hask> / <hask>pseq</hask> tricks.<br />
<br />
<p><hask>seq</hask> is similar to <hask>pseq</hask> but provides a weaker guarantee. [http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg10973.html The details] are subtle; suffice to say that if you're controlling evaluation order, you want <hask>pseq</hask>.</p><br />
<br />
== How do I do event-based IO in GHC Haskell? Should I call <tt>select</tt>, <tt>epoll</tt>, etc? ==<br />
<br />
No; just do blocking IO from multiple threads, and GHC's runtime system will make these calls for you. GHC Haskell gives you the performance benefits of event-based IO without making you turn your code inside-out.<br />
<br />
Threads in GHC are lightweight — both in performance and in the mental effort of using them. You can handle [http://blog.johantibell.com/2010/09/final-version-of-our-ghc-io-manager.html ten thousand concurrent requests] at high throughput with a naive "one thread per client" model.<br />
<br />
== What's the difference between <hask>forkIO</hask> and <hask>forkOS</hask>? ==<br />
<br />
It only matters if you're calling into a C library that cares about thread-local state. In that case, <hask>forkOS</hask> guarantees that the C library will see the same OS thread each time. Any difference beyond that is an implementation detail and subject to change.<br />
<br />
== How can I wait for a thread to finish and produce a result? ==<br />
<br />
There's a few libraries for this on Hackage, like [http://hackage.haskell.org/package/async <tt>async</tt>], [http://hackage.haskell.org/package/spawn <tt>spawn</tt>], and [http://hackage.haskell.org/package/threads <tt>threads</tt>].<br />
<br />
It's not hard to implement this yourself using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html <tt>MVar</tt>], though it's harder to get the exception handling right.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41647FAQ2011-08-16T12:00:34Z<p>Keegan: add questions about concurrency and parallelism</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
= Concurrency and parallelism =<br />
<br />
See also notes on [[parallel]] and [[Concurrency|concurrent]] programming.<br />
<br />
== What's the difference between concurrency and parallelism? ==<br />
<br />
Briefly: concurrency describes semantics; parallelism describes an implementation property.<br />
<br />
Concurrent programs are written with explicit threads of control. Concurrent semantics fit naturally with certain real-world problems, like a network server talking to many simultaneous clients. This is still a nice model for writing a network server, even if you only intend to run it on one CPU core — concurrency without parallelism.<br />
<br />
Parallel programs are those which run on multiple CPU cores simultaneously, regardless of how they were implemented.<br />
<br />
Concurrency is a popular way to obtain parallel performance, but converting a pure computation to use concurrent semantics is difficult and error-prone. GHC Haskell provides "[http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html semi-implicit parallelism]" as an alternative. Adding these "annotations" to a program cannot change its behavior.<br />
<br />
There's a longer discussion on the [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ GHC blog].<br />
<br />
== How do <hask>par</hask>, <hask>pseq</hask>, and <hask>seq</hask> relate? ==<br />
<br />
The expression <hask>par x y</hask> is semantically equivalent to <hask>y</hask>, but suggests to the runtime system that evaluating <hask>x</hask> in parallel might be a good idea. Usually <hask>x</hask> would be a variable referring to a thunk (unevaluated expression) that will later be needed.<br /><br /><br />
<br />
Now consider <hask>par x (x+y)</hask>. Evaluating this expression suggests evaluating <hask>x</hask> in parallel. But before the runtime system can act on that suggestion, we evaluate <hask>(x+y)</hask>, which will evaluate both <hask>x</hask> and <hask>y</hask> in sequence. It would be better to work on <hask>y</hask> for a while, and only demand <hask>x</hask> later, after perhaps some parallel work has occurred. We can use <hask>pseq</hask> to force this evaluation order, as in <hask>par x (pseq y (x+y))</hask>.<br /><br /><br />
<br />
The [http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel-Strategies.html Strategies] module provides a nicer interface to these <hask>par</hask> / <hask>pseq</hask> tricks.<br />
<br />
<p><hask>seq</hask> is similar to <hask>pseq</hask> but provides a weaker guarantee. [http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg10973.html The details] are subtle; suffice to say that if you're controlling evaluation order, you want <hask>pseq</hask>.</p><br />
<br />
== How do I do event-based IO in GHC Haskell? Should I call <tt>select</tt>, <tt>epoll</tt>, etc? ==<br />
<br />
No; just do blocking IO from multiple threads, and GHC's runtime system will make these calls for you. GHC Haskell gives you the performance benefits of event-based IO without making you turn your code inside-out.<br />
<br />
Threads in GHC are lightweight — both in performance and in the mental effort of using them. You can handle [http://blog.johantibell.com/2010/09/final-version-of-our-ghc-io-manager.html ten thousand requests per second] with a naive "one thread per client" model.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41646FAQ2011-08-16T11:41:01Z<p>Keegan: fix formatting</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41638FAQ2011-08-16T08:26:47Z<p>Keegan: add section on modules</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <hask>IORef</hask>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= Modules =<br />
<br />
== How do I deal with name clashes between modules? ==<br />
<br />
You can disambiguate by prefixing a module name:<br />
<br />
<haskell><br />
import Data.List<br />
import Data.Map<br />
<br />
f = Data.List.lookup 7<br />
g = Data.Map.lookup 7<br />
</haskell><br />
<br />
The import syntax gives you additional control:<br />
<br />
* With <hask>import qualified Foo</hask> the names from <hask>Foo</hask> can ''only'' be used qualified, and won't clash with unqualified names.<br />
<br />
* With <hask>import Foo as M</hask> you'd write <hask>M.x</hask> instead of <hask>Foo.x</hask>.<br />
<br />
You can combine these two features. A more common way to write the above example is:<br />
<br />
<haskell><br />
import qualified Data.Map as M<br />
<br />
f = lookup 7 -- unqualified, from Prelude<br />
g = M.lookup 7<br />
</haskell><br />
<br />
In general, most combinations of <hask>import</hask> features are allowed. You<br />
can combine <hask>as</hask> and <hask>qualified</hask> with import and<br />
<hask>hiding</hask> lists. You can import two modules <hask>as</hask> the same<br />
name, or one module <hask>as</hask> two names, with different import and<br />
<hask>hiding</hask> lists, <hask>qualified</hask> or unqualified, etc.<br />
<br />
== How do I control the <hask>Prelude</hask> import? ==<br />
<br />
Haskell modules implicitly import <hask>Prelude</hask>, unless an explicit import is given. So you can write<br />
<br />
<haskell><br />
import Prelude as P hiding (length, head)<br />
</haskell><br />
<br />
== How do I qualify the name of an infix operator? ==<br />
<br />
You prefix the module name, as usual:<br />
<br />
<haskell><br />
x = 2 + 3<br />
y = 2 Prelude.+ 3<br />
<br />
f = (+) 7<br />
g = (Prelude.+) 7<br />
</haskell><br />
<br />
This looks weird but works fine. The syntax does clash a bit:<br />
<br />
<haskell><br />
xs = [False..True] -- wrong, parses as qualified name<br />
xs = [False .. True] -- ok<br />
</haskell><br />
<br />
== How do I mention an infix operator in an export / import / <hask>hiding</hask> list? ==<br />
<br />
The same way as elsewhere: enclose it in parentheses.<br />
<br />
<haskell><br />
import Prelude ( succ, (+), length, (*) )<br />
</haskell><br />
<br />
== I listed a data type in my import list but its data constructors aren't in scope. How do I fix it? ==<br />
<br />
You have to import data constructors explicitly:<br />
<br />
<haskell><br />
import Prelude ( Maybe ) -- the type only<br />
import Prelude ( Maybe(Nothing) ) -- type and specific constructor(s)<br />
import Prelude ( Maybe(..) ) -- type and all its constructors<br />
</haskell><br />
<br />
== How can I import and re-export a whole module? ==<br />
<br />
<haskell><br />
module Bar ( module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
== How can I export another module ''and'' everything defined in this module? ==<br />
<br />
<haskell><br />
module Bar ( module Bar, module Foo ) where<br />
import Foo<br />
</haskell><br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41608FAQ2011-08-15T00:26:51Z<p>Keegan: more code formatting</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <hask>IORef</hask>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <hask>Integer</hask> and <hask>Int</hask>? ==<br />
<br />
<p><hask>Integer</hask> can represent arbitrarily large integers, up to using all of the storage on your machine.</p><br />
<br />
<p><hask>Int</hask> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.</p><br />
<br />
Operations on <hask>Int</hask> can be much faster than operations on <hask>Integer</hask>, but overflow and underflow can cause weird bugs. Using <hask>Int</hask> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <hask>length</hask>, <hask>take</hask>) use <hask>Int</hask>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <hask>A -> B</hask>. For example, you can convert <hask>Double</hask> to <hask>Int</hask> with <hask>round</hask>, <hask>ceiling</hask>, or <hask>floor</hask>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <hask>Int</hask> to a <hask>Double</hask> which represents the same integer. In this case you'd just use a function of type <hask>Int -> Double</hask>, such as <hask>fromIntegral</hask>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br /><br /><br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <hask>x :: Int</hask> to <hask>show :: (Show a) => a -> String</hask>, which automatically specializes the type of <hask>show</hask> to <hask>Int -> String</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <hask>cast</hask> returning <hask>Nothing</hask>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br /><br /><br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<p><hask>fromIntegral</hask> converts to a wider range of types, but <hask>realToFrac</hask> converts from types which aren't integers.</p><br />
<br />
== How do I convert <hask>Maybe Int</hask> to <hask>Int</hask>? ==<br />
<br />
Use pattern-matching. If <hask>mx :: Maybe Int</hask>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <hask>Nothing</hask> case, and is the main advantage of <hask>Maybe</hask>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <hask>fromJust</hask>, because passing <hask>Nothing</hask> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <hask>Nothing</hask>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <hask>Nothing</hask> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <hask>IO Int</hask> to <hask>Int</hask>? ==<br />
<br />
You can't; they represent totally different things. An <hask>Int</hask> is an integer. An <hask>IO Int</hask> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <hask>String</hask> (or <hask>Text</hask>) and <hask>ByteString</hask>? ==<br />
<br />
<p><hask>String</hask> represents a sequence of Unicode characters. <hask>ByteString</hask> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.</p><br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <hask>read</hask> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <hask>let</hask>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <hask>undefined</hask>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <hask>IO</hask> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <hask>State s</hask> and <hask>ST s</hask> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <hask>s -> (a, s)</hask>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <hask>State</hask> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<hask>ST</hask> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <hask>STRef</hask> and <hask>IORef</hask> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <hask>runST</hask>.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41607FAQ2011-08-15T00:10:06Z<p>Keegan: add answer about type vs. data vs. newtype</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <tt>Nothing</tt> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
== What's the difference between <hask>type</hask>, <hask>data</hask>, and <hask>newtype</hask>? ==<br />
<br />
<p><hask>type</hask> introduces a synonym, which is fully interchangeable with the original type:</p><br />
<br />
<haskell><br />
type Foo = Int<br />
<br />
main = print ((2 :: Int) + (3 :: Foo))<br />
</haskell><br />
<br />
So it provides convenience and documentation, but no additional type checking.<br />
<br />
<p><hask>data</hask> is used to define new data types, distinct from any existing type.</p><br />
<br />
<p><hask>newtype</hask> can mostly be understood as a restricted form of <hask>data</hask>. You can use <hask>newtype</hask> when you have exactly one constructor with exactly one field. In those cases, <hask>newtype</hask> can give better performance than <hask>data</hask>.</p><br />
<br />
There is, however, a [[Newtype|subtle difference]] between <hask>data</hask> and <hask>newtype</hask> semantics, which is why the <hask>newtype</hask> optimization is not applied automatically.<br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41580FAQ2011-08-14T06:12:14Z<p>Keegan: add to Category:FAQ</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <tt>Nothing</tt> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.<br />
<br />
[[Category:FAQ]]</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41579FAQ2011-08-14T03:00:48Z<p>Keegan: additional Maybe example</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
If you pattern-match without a <tt>Nothing</tt> case:<br />
<br />
<haskell><br />
let Just x = mx in ...<br />
</haskell><br />
<br />
you'll at least get a line number in the error message:<br />
<br />
<pre><br />
*** Exception: foo.hs:2:9-24: Irrefutable pattern failed for pattern Data.Maybe.Just x<br />
</pre><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41578FAQ2011-08-14T02:02:39Z<p>Keegan: fix link</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What a Monad is not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41577FAQ2011-08-14T02:00:19Z<p>Keegan: wiki links</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from [[IRC channel|<tt>#haskell</tt> IRC]]. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other [[tutorials]], [[books]], and [[Learning Haskell|other resources]] are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* [[IRC channel|<tt>#haskell</tt> on Freenode IRC]]<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of [[Haskell in industry|companies using Haskell]], but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The [[Language and library specification|latest version of the spec]] is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other [[implementations]] of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with [[Cabal-Install|<tt>cabal-install</tt>]].<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; [[Introduction to IO|IO in Haskell]] is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an [[existential type]], possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;[[What monads are not]]&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;[[Typeclassopedia]]&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the [[Introduction to IO]].<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keeganhttps://wiki.haskell.org/index.php?title=Introduction&diff=41576Introduction2011-08-14T01:50:07Z<p>Keegan: /* Other frequently-asked questions */ link to FAQ</p>
<hr />
<div>[[Category:Tutorials]] [[Category:Language]]<br />
Haskell is a computer programming language. In particular, it is a<br />
'' [[Polymorphism|polymorphically]] [[typing|statically typed]], [[Lazy evaluation|lazy]], [[functional programming|purely functional]] '' language,<br />
quite different from most other programming languages. <br />
The language is named for [[Haskell Brooks Curry]], whose work in mathematical logic serves as a foundation for<br />
functional languages. <br />
Haskell is based on the ''[[lambda calculus]]'', hence the lambda we use as a logo.<br />
<br />
<br />
==Why use Haskell?==<br />
Writing large software systems that<br />
work is difficult and expensive. Maintaining those systems is even<br />
more difficult and expensive. Functional programming languages, such<br />
as Haskell, can make it easier and cheaper. For example, a new user who<br />
wrote a small relational DBMS in Haskell had this to say:<br />
<blockquote><br />
WOW! I basically wrote this without testing just thinking about my<br />
program in terms of transformations between types. I wrote the<br />
test/example code and had almost no implementation errors in the code! The<br />
compiler/type-system is really really good at preventing you from<br />
making coding mistakes! I've never in my life had a block of code<br />
this big work on the first try. I am WAY impressed.<br />
</blockquote><br />
Even if you are not in a position to use Haskell in your programming projects, learning Haskell can make you a better programmer in any language. <br />
<blockquote><br />
I learned Haskell a couple of years ago, having previously programmed in<br />
Python and (many) other languages. Recently, I've been using Python for a<br />
project (the choice being determined by both technical and non-technical<br />
issues), and find my Python programming style is now heavily influenced (for the better, I hope ;-) by my Haskell programming experience.<br><br><br />
Graham Klyne<br />
</blockquote><br />
<br />
<br />
Haskell offers you:<br />
<br />
*Substantially increased programmer productivity (Ericsson measured an improvement factor of between 9 and 25 using Erlang, a functional programming language similar to Haskell, in one set of experiments on telephony software).<br />
*Shorter, clearer, and more maintainable code.<br />
*Fewer errors, higher reliability.<br />
*A smaller &quot;semantic gap&quot; between the programmer and the language.<br />
*Shorter lead times.<br />
<br />
Haskell is a wide-spectrum language, suitable for a variety of<br />
applications. It is particularly suitable for programs which need to<br />
be highly modifiable and maintainable.<br />
<br />
Much of a software product's life is spent in ''specification'',<br />
''design'' and ''maintenance'', and not in ''programming''.<br />
Functional languages are superb for writing specifications which can<br />
actually be executed (and hence tested and debugged). Such a<br />
specification then ''is'' the first prototype of the final<br />
program.<br />
<br />
Functional programs are also relatively easy to maintain, because the<br />
code is shorter, clearer, and the rigorous control of side effects<br />
eliminates a huge class of unforeseen interactions.<br />
<br />
==What is functional programming?==<br />
C, Java, Pascal, Ada, and so on, are all ''imperative''<br />
languages. They are &quot;imperative&quot; in the sense that they<br />
consist of a sequence of commands, which are executed strictly one<br />
after the other. Haskell is a ''functional'' language. A<br />
functional program is a single expression, which is executed by<br />
evaluating the expression. <br />
<br />
Anyone who has used a spreadsheet has experience of functional<br />
programming. In a spreadsheet, one specifies the value of each cell<br />
in terms of the values of other cells. The focus is on ''what'' is<br />
to be computed, not ''how'' it should be computed. For<br />
example:<br />
*we do not specify the order in which the cells should be calculated -&nbsp;instead we take it for granted that the spreadsheet will compute cells in an order which respects their dependencies.<br />
*we do not tell the spreadsheet how to allocate its memory - rather, we expect it to present us with an apparently infinite plane of cells, and to allocate memory only to those cells which are actually in use.<br />
*for the most part, we specify the value of a cell by an ''expression'' (whose parts can be evaluated in any order), rather than by a ''sequence of commands '' which computes its value.<br />
<br />
An interesting consequence of the spreadsheet's unspecified order<br />
of re-calculation is that the notion of assignment is not very useful.<br />
After all, if you don't know exactly when an assignment will<br />
happen, you can't make much use of it! This contrasts strongly<br />
with programs in conventional languages like C, which consist<br />
essentially of a carefully-specified sequence of assignments, or Java,<br />
in which the ordering of method calls is crucial to the meaning of a<br />
program. <br />
<br />
This focus on the high-level &quot;what&quot; rather than the<br />
low-level &quot;how&quot; is a distinguishing characteristic of<br />
functional programming languages.<br />
<br />
Another well-known nearly-functional language is the standard database<br />
query language SQL. An SQL query is an expression involving<br />
projections, selections, joins and so forth. The query says what<br />
relation should be computed, without saying how it should be computed.<br />
Indeed, the query can be evaluated in any convenient order. SQL<br />
implementations often perform extensive query optimization which<br />
(among other things) figures out the best order in which to evaluate<br />
the expression.<br />
<br />
==What's good about functional programming?==<br />
<br />
Spreadsheets and SQL are both fairly specialized languages. Functional<br />
programming languages take the same ideas and move them into the realm<br />
of general-purpose programming. To get an idea of what a functional<br />
program is like, and the expressiveness of functional languages, look at<br />
the following quicksort programs. They both sort a sequence of numbers<br />
into ascending order using a standard method called "quicksort". The<br />
first program is written in Haskell and the second in C. <br />
<br />
Whereas the C program describes the particular steps the machine must<br />
make to perform a sort -- with most code dealing with the low-level<br />
details of data manipulation -- the Haskell program encodes the sorting<br />
algorithm at a much higher level, with improved brevity and clarity as<br />
a result (at the cost of efficiency unless compiled by a very smart compiler):<br />
<br />
===Quicksort in Haskell===<br />
The first thing to know about Haskell's syntax is that parentheses are used just for grouping of operands and not for functional application, which is indicated just by a juxtaposition of a function and its arguments - which also has the highest priority, so is always applied before any operators: here, the <code>++</code> operator has lower precedence than the two <code>quicksort</code> calls (the parentheses around them are superfluous and are put here for clarity):<br />
<br />
<haskell><br />
quicksort :: Ord a => [a] -> [a]<br />
quicksort [] = []<br />
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)<br />
where<br />
lesser = filter (< p) xs<br />
greater = filter (>= p) xs<br />
<br />
</haskell><br />
This looks superficially like Lisp, but the parentheses only indicate the grouping of operands on the right-hand side of equations (they indicate ''patterns'' of a function's argument(s), on the left-hand side).<br />
<br />
Here <code>[]</code> stands for empty list, <code>[p]</code> for a singleton list holding one element <code>p</code>, <code>++</code> is a built-in list concatenation operator, and the two <code>filter</code> calls use two on-the-fly built predicates, first for getting all the elements of <code>xs</code> that are smaller than the pivot element <code>p</code>, and the other - all those greater than, or equal to it.<br />
<br />
This definition uses Haskell's ability to define functions as equations with pattern-matching clauses: here the first one, with <code>[]</code> pattern for an empty list on its left-hand side, and the second, with <code>(p:xs)</code> pattern on its left-hand side standing for non-empty list with the head element <code>p</code> (used as a pivot element), and the tail <code>xs</code> (which is read, by convention, as ''axes'', suggesting that it is a list of several ''xs'', viz. elements ''"x"'').<br />
<br />
The very first line above is the function's ''type signature'': it says that <code>quicksort</code> transforms a list of elements of some type <code>a</code> (usually read "alpha") into a list of the same type, for a type <code>a</code> that is an instance of typeclass <code>Ord</code> (which means that comparison operations are defined for it, so elements of type <code>a</code> can be compared with one another).<br />
<br />
===Quicksort in C===<br />
<br />
True quicksort in C sorts in-place:<br />
<pre><br />
// To sort array a[] of size n: qsort(a,0,n-1)<br />
<br />
void qsort(int a[], int lo, int hi) <br />
{<br />
int h, l, p, t;<br />
<br />
if (lo &lt; hi) {<br />
l = lo;<br />
h = hi;<br />
p = a[hi];<br />
<br />
do {<br />
while ((l &lt; h) &amp;&amp; (a[l] &lt;= p)) <br />
l = l+1;<br />
while ((h &gt; l) &amp;&amp; (a[h] &gt;= p))<br />
h = h-1;<br />
if (l &lt; h) {<br />
t = a[l];<br />
a[l] = a[h];<br />
a[h] = t;<br />
}<br />
} while (l &lt; h);<br />
<br />
a[hi] = a[l];<br />
a[l] = p;<br />
<br />
qsort( a, lo, l-1 );<br />
qsort( a, l+1, hi );<br />
}<br />
}<br />
</pre><br />
<br />
A [[/Direct Translation | semi-direct translation]] of the C code is here.<br />
<br />
Let's examine some of the benefits of Haskell and functional programming.<br />
A more detailed case for functional programming can be found in <br />
<br />
<BLOCKQUOTE><br />
[http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf '''Why Functional Programming Matters'''] by [http://www.cse.chalmers.se/~rjmh/ John Hughes], The Computer<br />
Journal, Vol. 32, No. 2, 1989, pp. 98 - 107. Also in: David A. Turner<br />
(ed.): Research Topics in Functional Programming, Addison-Wesley,<br />
1990, pp. 17 - 42. <br />
</BLOCKQUOTE><br />
A slightly less formal essay inspired by the paper above can be found in<br />
<BLOCKQUOTE><br />
[[Why Haskell matters |'''Why Haskell Matters''']] originally by [mailto:sylvan@dtek.chalmers.se Sebastian Sylvan]<br />
</BLOCKQUOTE><br />
<br />
===Ease of understanding===<br />
Functional programs are often easier to '''understand''': it is usually possible to get their meaning at a glance. The same certainly cannot be said of the C program. It takes quite a while to understand, and even when you do understand it, it is extremely easy to make a small slip and end up with an incorrect program. <br />
<br />
Here is a detailed explanation of the Haskell quicksort:<br />
<br />
<haskell><br />
quicksort [] = []<br />
</haskell><br />
The first clause reads: "When you sort an empty list (<tt>[]</tt>), the result is just an empty list". <br />
<br />
<haskell><br />
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)<br />
where<br />
lesser = filter (< p) xs<br />
greater = filter (>= p) xs<br />
</haskell><br />
The second clause reads: "To sort a list whose first element will be henceforth referred to as <tt>p</tt> and<br />
the rest of which will be referred to as <tt>xs</tt>, sort the elements of <tt>xs</tt> that are less than <tt>p</tt>, sort the elements of <tt>xs</tt> that are greater than or equal to <tt>p</tt>, and concatenate (<tt>++</tt>) the results, with <tt>p</tt> sandwiched in the middle."<br />
<br />
===Brevity===<br />
Functional programs tend to be much more '''concise''' than their<br />
imperative counterparts. Quicksort is a rather extreme case, but in<br />
general functional programs are much shorter (by a factor of two to ten).<br />
<br />
The above could be written even more concisely with the help of [[list comprehension]]s:<br />
<haskell><br />
qsort (p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]<br />
</haskell><br />
<br />
The first sub-expression means, for <code>x</code> drawn from <code>xs</code> in order, such that <code>x < p</code>, collect <code>x</code>s in a list and call the <code>qsort</code> function with it, recursively. Similarly for the last one.<br />
<br />
===No core dumps===<br />
Most functional languages, and Haskell in particular, are '''strongly<br />
typed''', eliminating a huge class of easy-to-make errors at compile<br />
time. In particular, strong typing means '''no core dumps'''!<br />
There is simply no possibility of treating an integer as a pointer, or<br />
following a null pointer.<br />
<br />
===Code re-use===<br />
Of course, strong typing is available in many imperative languages, such as Ada or Pascal. However, Haskell's type system is much less restrictive than, say, Pascal's, because it uses '''[[polymorphism]]'''.<br />
<br />
For example, the qsort program given in Figure 1 will not only sort lists of integers, but also lists of floating point numbers, lists of characters, lists of lists; indeed, it will sort lists of ''anything'' for which it is meaningful to have "less-than" and "greater-than" operations. In contrast, the C version can only sort an array of integers, and nothing else.<br />
<br />
Polymorphism enhances re-usability.<br />
<br />
===Strong glue===<br />
"Non-strict" functional languages, such as Haskell, have another powerful feature: they<br />
only evaluate as much of the program as is required to get the answer<br />
- this is called [[Haskell/Lazy evaluation |'''lazy evaluation''']]. This feature is rather<br />
like Unix pipes. For example, the Unix command<br />
<pre><br />
grep printf Foo.c | wc<br />
</pre><br />
counts the number of lines in the file <tt> Foo.c </tt>that include the<br />
string <tt>printf</tt>.<br />
The command <br />
<pre><br />
grep printf Foo.c<br />
</pre><br />
produces all lines which contain the string &quot;<tt>printf</tt>&quot;,<br />
while the &quot;<tt>wc</tt>&quot; command counts them. The pipe,<br />
written &quot;<tt>|</tt>&quot;, takes the output from the first command<br />
and delivers it to the second. The two commands execute together, so<br />
that the output of the first is consumed more-or-less immediately by<br />
the second. In this way, no large intermediate files need be<br />
produced. You can think of <tt>wc</tt> &quot;demanding&quot;<br />
lines from the <tt>grep</tt>.<br />
<br />
If the second command only needs some of the output of the first, then<br />
execution of the first command might never need to be completed. For<br />
example,<br />
<br />
<pre><br />
grep printf Foo.c | head 5<br />
</pre><br />
just prints the first 5 lines which contain &quot;<tt>printf</tt>&quot;.<br />
There is no need to modify the <tt>grep</tt> command to take account of<br />
the fact that its execution might be abandoned.<br />
<br />
[[Lazy vs. non-strict |Non-strict]] languages provide exactly this kind of demand-driven<br />
evaluation. Data structures are evaluated just enough to deliver the<br />
answer, and parts of them may not be evaluated at all. As in the case<br />
of Unix commands, this provides powerful &quot;glue&quot; with which<br />
to compose existing programs together. What this means is that it is<br />
possible to '''re-use programs''', or pieces of programs, much more<br />
often than can be done in an imperative setting. [[Haskell/Lazy evaluation |Lazy evaluation]] allows us to write more '''[[modular programs]]'''.<br />
<br />
===Powerful abstractions===<br />
In general, functional languages offer powerful new ways to<br />
encapsulate '''abstractions'''. An abstraction allows you to define<br />
an object whose internal workings are hidden; a C procedure, for<br />
example, is an abstraction. Abstractions are ''the'' key to<br />
building modular, maintainable programs, so much so that a good<br />
question to ask of any new language is "what mechanisms for<br />
abstraction does it provide?". <br />
<br />
One powerful abstraction mechanism available in functional languages<br />
is the '''[[higher order function]]'''. In Haskell a function is a<br />
first-class citizen: it can freely be passed to other functions,<br />
returned as the result of a function, stored in a data structure, and<br />
so on. It turns out that the judicious use of higher order functions<br />
can substantially improve the structure and modularity of many<br />
programs.<br />
<br />
===Built-in memory management===<br />
Very many sophisticated programs need to allocate dynamic memory from a heap. In C this is done with a call to <tt> malloc</tt>, followed by code to initialize the store just allocated. The programmer is responsible for returning the store to the free pool when it isn't needed any more, a notorious source of "dangling-pointer" errors. To make matters worse, <tt>malloc</tt> is fairly expensive performance-wise, so programmers often <tt>malloc</tt> a single large chunk of store, and then allocate "by hand" out of this.<br />
<br />
Every functional language relieves the programmer of this storage management burden. Store is allocated and initialized implicitly, and recovered automatically by the garbage collector. The technology of storage allocation and garbage collection is now well developed, and the performance costs are rather slight.<br />
<br />
==When C is better==<br />
It isn't all roses, of course. The C quicksort uses an extremely<br />
ingenious technique, invented by Hoare, whereby it sorts the array<br />
''in place''; that is, without using any extra storage. As a<br />
result, it runs quickly, and in a small amount of memory. In<br />
contrast, the Haskell program allocates quite a lot of extra memory<br />
behind the scenes, and runs rather slower than the C program. <br />
<br />
In effect, the C quicksort does some very ingenious storage<br />
management, trading this algorithmic complexity for a reduction in<br />
run-time storage management costs.<br />
<br />
In applications where [[performance]] is required at any cost, or when the<br />
goal is detailed tuning of a low-level algorithm, an imperative<br />
language like C would probably be a better choice than Haskell,<br />
exactly because it provides more intimate control over the exact way<br />
in which the computation is carried out - that is, until sufficiently smart compiler appears that is able to derive the C equivalent from the Haskell one-liner, all by itself.<br />
<br />
===Functional vs imperative===<br />
But few programs require performance at any cost! After all, we all<br />
stopped writing assembly-language programs, except perhaps for key<br />
inner loops, long ago. The benefits of having a more supportive<br />
programming model (an arbitrary number of named, local variables<br />
instead of a fixed number of registers, for example) far outweigh the<br />
modest run-time costs.<br />
<br />
Similarly, we willingly accept the costs of a virtual memory paging<br />
system, in exchange for the more supportive programming model of an<br />
infinite virtual address space. The days of explicit memory overlays<br />
are over.<br />
<br />
Functional languages take another large step towards a higher-level<br />
programing model. Programs are easier to design, write and maintain,<br />
but the language offers the programmer less control over the machine.<br />
For most programs the result is perfectly acceptable.<br />
<br />
==What is Haskell?==<br />
Haskell is a modern, standard, non-strict, purely-functional<br />
programming language. It provides all the features sketched above,<br />
including polymorphic typing, lazy evaluation and higher-order<br />
functions. It also has an innovative type system which supports a<br />
systematic form of overloading and a module system.<br />
<br />
It is specifically designed to handle a wide range of applications,<br />
from numerical through to symbolic. To this end, Haskell has an<br />
expressive syntax, and a rich variety of built-in data types,<br />
including arbitrary-precision integers and rationals, as well as the<br />
more conventional integer, floating-point and boolean types.<br />
<br />
There are a number of [[compilers and interpreters]] available. All are<br />
free. First-time users may want to start with [[Hugs]], a small, portable Haskell interpreter. <br />
<br />
See also [[History of Haskell|the History of Haskell]]<br />
<br />
==Does anyone use functional programming?==<br />
Functional programming languages are used in substantial applications.<br />
For example:<br />
* Software AG, a major German software company, market an expert system (Natural Expert) which is programmed in a functional language. Their users find it easy to develop their applications in this language, through which they gain access to an underlying database system. It all runs on an IBM mainframe.<br />
*Ericsson have developed a new functional language, Erlang, to use in their future telephony applications. They have already written 130k-line Erlang applications, and find them very much shorter and faster to develop.<br />
*Amoco ran an experiment in which they re-coded in Miranda, a lazy functional language, a substantial fraction of their main oil-reservoir simulation code, a critical application. The resulting program was vastly shorter, and its production revealed a number of errors in the existing software. Amoco subsequently transcribed the functional program into C++ with encouraging results.<br />
*A researcher at the MITRE corporation is using Haskell to prototype his digital signal-processing applications.<br />
*Researchers at Durham University used Miranda, and later Haskell, in a seven-year project to build LOLITA, a 30,000-line program for natural-language understanding.<br />
*Query is the query language of the O2 object-oriented database system. O2Query is probably the most sophisticated commercially-available object-oriented database query language and it is a functional language.<br />
*ICAD Inc market a CAD system for mechanical and aeronautical engineers. The language in which the engineers describe their design is functional, and it uses lazy evaluation extensively to avoid recomputing parts of the design which are not currently visible on the screen. This results in substantial performance improvements.<br />
*An incestuous example: the Glasgow Haskell compiler is written in Haskell: a 100,000-line application.<br />
*[http://pugscode.org Pugs], the leading perl6 implementation is written in Haskell<br />
*As is [http://darcs.net Darcs], a cutting edge distributed revision control system<br />
<br />
Some other examples of [[Haskell in practice]].<br />
<br />
Clifford Beshers, of [http://www.linspire.com/ Linspire Inc]., describes their experience with Haskell, and functional programming:<br />
<br />
<blockquote><br />
Linspire, Inc. has used functional programming since its inception in<br />
2001, beginning with extensive use of O'Caml, with a steady shift to<br />
Haskell as its implementations and libraries have matured. Hardware<br />
detection, software packaging and CGI web page generation are all areas<br />
where we have used functional programming extensively.<br />
</blockquote><br />
<br />
<blockquote><br />
Haskell's feature set lets us replace much of our use of little<br />
languages (e.g., bash or awk) and two-level languages (C or C++ bound to<br />
an interpreted language), allowing for faster development, better code<br />
sharing and ultimately faster implementations. Above all, we value<br />
static type checking for minimizing runtime errors in applications that<br />
run in unknown environments and for wrapping legacy programs in strongly<br />
typed functions to ensure that we pass valid arguments.<br />
</blockquote><br />
<br />
==Other frequently-asked questions==<br />
<br />
There is also a [[FAQ|larger FAQ]] in progress.<br />
<br />
===''Is functional programming hard to learn?''===<br />
<blockquote><br />
Functional programming does require a change in perspective, which<br />
some programmers find hard. But Ericsson's experience in training<br />
programmers in Erlang is that most find the transition easy -<br />
provided they take the training need seriously rather than assuming<br />
that they can "pick it up on the day".<br />
</blockquote><br />
===''Aren't functional programs very slow?''===<br />
<blockquote>They used to be, perhaps 20 years ago. But the compilers<br />
have long since caught up. Haskell programs run fast for all but the<br />
most performance-demanding applications. At the time of writing, Haskell<br />
compiled via GHC is in 2nd place (behind C) in the <br />
[http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all Great Language Shootout],<br />
with other functional languages also ranked highly.<br />
</blockquote><br />
<br />
===''I already have a large application in C or C++.''===<br />
Also worded as: ''Can I benefit from functional programming without rewriting my whole system?''<br />
<blockquote><br />
<br />
Haskell has been successfully integrated into existing applications in<br />
a number of ways. <br />
[http://www.haskell.org/hdirect/ HaskellDirect] is<br />
an IDL (Interface Description Language) based tool that allows Haskell<br />
programs to work with software components. Low level C/C++ interfaces<br />
can be generated with<br />
[http://www.haskell.org/greencard Green Card] or <br />
[http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ C->Haskell], allowing <br />
tight integration between Haskell and C. These tools have been used<br />
to build a large number of successful, mixed language systems.<br />
</blockquote><br />
<br />
==='' What libraries does Haskell support?''===<br />
<blockquote><br />
Many software libraries have been developed for Haskell. See the<br />
[[Libraries and tools| list of Haskell libraries]] for a list of much of<br />
what is available.<br />
<br />
</blockquote><br />
<br />
==='' What other software tools for Haskell are there? ''===<br />
<blockquote><br />
Glasgow Haskell comes with a profiler which allows you to find which<br />
parts of your program are consuming most time and space. Chalmers<br />
Haskell has a space-profiling tool, and a quasi-parallel simulator<br />
which allows you to experiment with running your program in<br />
parallel. Hugs also has some similar tools. For a complete list, check<br />
the [[Libraries and tools|tools page]].<br />
</blockquote><br />
<br />
===''How can I ask for help?''===<br />
There is a large community of haskell users willing to help. They can be contacted on maillists, IRC, or StackOverflow<br />
<br />
<br />
===''Can I get a support contract or a help-line?''===<br />
<blockquote><br />
It used to be the case that if you wanted help, you had to persuade a<br />
Haskell research group that your problem was interesting enough or<br />
important enough that they should spend time helping you for free.<br />
<br><br />
Whilst that is still an option, there is now a<br />
[[Consultants|directory of Haskell Consultants]] who provide:<br />
<br />
*Support for compilers, tools and libraries.<br />
*Help with improving code quality (time, space, robustness, maintainability, etc.) using code reviews and tools.<br />
*Help with using libraries, tools and advanced Haskell features such as type system extensions, exception handling, the foreign function interface, test harnesses, and concurrency.<br />
*Library and application development.<br />
*Staff training.<br />
<br />
These companies and individuals tend to work closely with those<br />
developing Haskell (indeed, they have usually made major<br />
contributions to Haskell themselves). <br />
<br />
</blockquote><br />
===''How can I learn Haskell?''===<br />
<blockquote><br />
The easiest way to learn Haskell is with a [[Books|textbook]]. There are a lot of [[Tutorials|online tutorials]], but you'll have a much easier time to learn the basics from a book. After all, Haskell is very different from traditional mainstream languages, it's like learning programming anew.<br />
</blockquote><br />
<br />
===''Comparisons to other languages''===<br />
<blockquote><br />
[[Comparison of functional programming languages | Click to see a table comparing features of Haskell to similar languages]]<br />
</blockquote><br />
<br />
''Based on a paper by Simon Peyton Jones.''</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41575FAQ2011-08-14T01:47:58Z<p>Keegan: format code</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from <tt>#haskell</tt> IRC. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other tutorials, books, and other resources are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* <tt>#haskell</tt> on Freenode IRC<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of companies using Haskell, but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The latest version of the spec is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other implementations of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with <tt>cabal-install</tt>.<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; IO in Haskell is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<haskell><br />
data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -> Whatever<br />
</haskell><br />
<br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an existential type, possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<haskell><br />
data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -> Monster<br />
, attack :: Monster -> Player -> Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...<br />
</haskell><br />
<br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<haskell><br />
fromIntegral :: (Integral a, Num b ) => a -> b<br />
realToFrac :: (Real a, Fractional b) => a -> b<br />
</haskell><br />
<br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<haskell><br />
case mx of<br />
Just x -> ...<br />
Nothing -> ...<br />
</haskell><br />
<br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<haskell><br />
let x = fromMaybe (error "custom error message") mx in ...<br />
</haskell><br />
<br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the Introduction to IO.<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<haskell><br />
reads :: (Read a) => String -> [(a, String)]<br />
</haskell><br />
<br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<haskell><br />
safeRead :: (Read a) => String -> Maybe a<br />
safeRead x = case reads x of<br />
[(v,"")] -> Just v<br />
_ -> Nothing<br />
</haskell><br />
<br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;What monads are not&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;Typeclassopedia&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the Introduction to IO.<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41574FAQ2011-08-14T01:43:33Z<p>Keegan: move "See also"</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from <tt>#haskell</tt> IRC. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* [[:Category:FAQ|Other FAQs]]<br />
* The [[Introduction|introduction to Haskell]], and the FAQ at the end of that document.<br />
<br />
__TOC__<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other tutorials, books, and other resources are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* <tt>#haskell</tt> on Freenode IRC<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of companies using Haskell, but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The latest version of the spec is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other implementations of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with <tt>cabal-install</tt>.<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; IO in Haskell is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<pre class="sourceCode literate haskell">data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -&gt; Whatever</pre><br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an existential type, possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<pre class="sourceCode literate haskell">data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -&gt; Monster<br />
, attack :: Monster -&gt; Player -&gt; Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...</pre><br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<pre class="sourceCode literate haskell">fromIntegral :: (Integral a, Num b ) =&gt; a -&gt; b<br />
realToFrac :: (Real a, Fractional b) =&gt; a -&gt; b</pre><br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<pre class="sourceCode literate haskell">case mx of<br />
Just x -&gt; ...<br />
Nothing -&gt; ...</pre><br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<pre class="sourceCode literate haskell">let x = fromMaybe (error &quot;custom error message&quot;) mx in ...</pre><br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the Introduction to IO.<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<pre class="sourceCode literate haskell">reads :: (Read a) =&gt; String -&gt; [(a, String)]</pre><br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<pre class="sourceCode literate haskell">safeRead :: (Read a) =&gt; String -&gt; Maybe a<br />
safeRead x = case reads x of<br />
[(v,&quot;&quot;)] -&gt; Just v<br />
_ -&gt; Nothing</pre><br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;What monads are not&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;Typeclassopedia&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the Introduction to IO.<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keeganhttps://wiki.haskell.org/index.php?title=FAQ&diff=41573FAQ2011-08-14T01:40:25Z<p>Keegan: first version of FAQ</p>
<hr />
<div>This FAQ is based on actual frequently-asked questions from <tt>#haskell</tt> IRC. The goal is simply to collect and edit some common answers. Beginner questions are still welcome on IRC, as always.<br />
<br />
This is a wiki, so please edit the text with any improvements you have. And feel free to add new questions, if they are frequently asked.<br />
<br />
== See also ==<br />
<br />
* The GHC FAQ.<br />
* The introduction to Haskell, and the FAQ at the end of that document.<br />
<br />
= The real world =<br />
<br />
== Should I learn Haskell? ==<br />
<br />
That depends on your goals. In general, Haskellers will tell you that you should learn Haskell. :)<br />
<br />
Learning Haskell is fun. It will expand your mind and make you a better programmer in other languages. These are the immediate benefits.<br />
<br />
Haskell is also a great tool for solving real-world problems, but it can take many months of study to get to that point.<br />
<br />
== Is Haskell hard to learn? ==<br />
<br />
Any competent programmer can learn Haskell, but it will take more time and motivation than you may expect.<br />
<br />
Haskell requires learning a new way to think, not just new syntax for old concepts. This can be incredibly frustrating, as simple tasks seem impossibly difficult.<br />
<br />
Those with no prior programming experience may actually have an easier time learning Haskell, because they have less to un-learn.<br />
<br />
== How can I get started with Haskell ''right now''? ==<br />
<br />
Check out [http://tryhaskell.org/ Try Haskell].<br />
<br />
== What should I read for learning Haskell? ==<br />
<br />
The most popular resources are [http://learnyouahaskell.com/ ''Learn You a Haskell''] and [http://book.realworldhaskell.org/ ''Real World Haskell'']. Each is available online for free, or can be purchased in hardcopy.<br />
<br />
Many other tutorials, books, and other resources are available.<br />
<br />
== How can I get help with learning Haskell? ==<br />
<br />
Your options include:<br />
<br />
* <tt>#haskell</tt> on Freenode IRC<br />
* [http://stackoverflow.com/questions/tagged/haskell Stack Overflow]<br />
* The [http://www.haskell.org/mailman/listinfo/haskell-cafe Haskell-Cafe] mailing list<br />
<br />
== Will Haskell get me a job? ==<br />
<br />
There are plenty of companies using Haskell, but it's still a tiny number compared to the software industry as a whole.<br />
<br />
There are also many companies which do not use Haskell, but prefer to hire people who know Haskell. It indicates that you learned something hard and obscure just for fun, which employers take as a sign of intelligence.<br />
<br />
== Is Haskell similar to Language X? ==<br />
<br />
Probably not. It's best if you approach Haskell with a clean slate. Most analogies to another language will break down somewhere, often in a subtle and misleading way. If you first learn the Haskell concepts for what they are, you can then draw useful connections to other languages.<br />
<br />
== What's the relationship between Haskell and GHC? ==<br />
<br />
Haskell is not a piece of software; it is a specification for a standardized programming language. The latest version of the spec is the Haskell 2010 Report.<br />
<br />
[http://www.haskell.org/ghc/ GHC] is the Glorious Glasgow Haskell Compiler. It is by far the most popular and &quot;production-ready&quot; implementation of the standard Haskell language. It also implements many [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html extension] features that go above and beyond standard Haskell. Many programs use these features and so aren't &quot;written in Haskell&quot; in the strictest sense.<br />
<br />
You can use the term &quot;Haskell&quot; to refer to the standard language, and &quot;GHC Haskell&quot; when including GHC extensions.<br />
<br />
Besides GHC, several other implementations of Haskell are available. Each one provides its own extensions, some of which don't exist in GHC.<br />
<br />
== What is the Haskell Platform? ==<br />
<br />
The [http://hackage.haskell.org/platform/ Haskell Platform] is a copy of GHC bundled with a &quot;blessed&quot; set of useful libraries. It is the easiest way to get started with Haskell. It's not essential to start with the Platform, because you can install the same libraries as needed.<br />
<br />
== What is Haskell Prime (Haskell')? ==<br />
<br />
[http://hackage.haskell.org/trac/haskell-prime/ Haskell Prime] is a process which produces new versions of the Haskell language spec. It does not refer to a particular present or future version of Haskell.<br />
<br />
== My textbook uses Haskell 98. Is it very different from Haskell 2010? ==<br />
<br />
No. Haskell 2010 is a [http://www.haskell.org/pipermail/haskell/2009-November/021750.html very conservative change] to Haskell 98. It fixes small syntactic flaws, and standardizes several well-behaved extensions which GHC has supported for years.<br />
<br />
The standardization process is very slow because standardizing a flawed language can be a costly mistake. Extensions are accepted only once they are considered mature and well-understood.<br />
<br />
== How do I get libraries for Haskell? ==<br />
<br />
You can find libraries on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage], and install them with <tt>cabal-install</tt>.<br />
<br />
== Is Haskell compiled? ==<br />
<br />
Usually. GHC, the most popular Haskell implementation, has an optimizing ahead-of-time native-code compiler, as well as a bytecode compiler and interpreter for interactive use.<br />
<br />
Haskell itself is not a &quot;compiled language&quot; because nothing in the Haskell spec requires implementations to be compilers.<br />
<br />
== Does Haskell have an interpreter? ==<br />
<br />
Yes, but maybe you instead mean &quot;Is there a program where I can type Haskell code and see it run immediately?&quot;. GHCi provides such a &quot;read-evaluate-print loop&quot;.<br />
<br />
= Paradigms =<br />
<br />
== Is learning Haskell the best way to learn functional programming? ==<br />
<br />
Not necessarily! Haskell is not a ''typical'' functional language. It can be overwhelming to learn the basic concepts of functional programming alongside static types, algebraic data, laziness, type classes, first-class IO, etc. For an introduction to FP by itself you might want to learn Scheme, or play with the FP features in your current favorite language.<br />
<br />
That said, many people choose Haskell as an introduction to FP and have success with that approach. Haskell has an extremely active community of people teaching, doing research, writing libraries, etc. Haskell is where interesting things happen in the FP space, so it's an exciting place to jump in.<br />
<br />
== I heard Haskell is pure functional. Does that mean I can't do imperative / OOP / aspect-oriented / logic programming in Haskell? ==<br />
<br />
No, &quot;pure functional&quot; has a specific technical meaning. It doesn't mean that functional is the only supported paradigm.<br />
<br />
Paradigms describe the techniques used in a particular program. For example, the Linux kernel is written in C, with pervasive use of functional, object-oriented, and aspect-oriented programming. The most we can say about a ''language'' is that it encourages or discourages a particular paradigm. Haskell is very flexible and can comfortably accommodate most paradigms, even when there is no built-in support.<br />
<br />
== I heard Haskell is pure functional. Does that mean it can't do IO? ==<br />
<br />
No; IO in Haskell is straightforward.<br />
<br />
== I heard Haskell is pure functional. Does that mean it doesn't have mutable state? ==<br />
<br />
No; see [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-IORef.html <tt>IORef</tt>] for a simple example. A more sophisticated example is [http://book.realworldhaskell.org/read/software-transactional-memory.html software transactional memory], which provides concurrent state more sophisticated than you'll find in most other imperative languages.<br />
<br />
== Wait, is Haskell imperative or is it functional? ==<br />
<br />
Both. In Haskell, functions are first class, and so are imperative actions.<br />
<br />
There is no reason to consider &quot;imperative language&quot; and &quot;functional language&quot; as opposites. It's only a historical accident that a few of the most popular imperative languages are unusually bad at functional programming. Functional imperative programming is extremely powerful and is supported by many languages.<br />
<br />
= Math =<br />
<br />
== Was Haskell designed by mathematicians? ==<br />
<br />
Haskell was designed by people studying programming language design. Perhaps programmers would consider them to be mathematicians, while mathematicians would consider them to be programmers.<br />
<br />
Designing a programming language is a hard thing to do. There are many non-obvious tradeoffs, and many lessons to be learned from past failures and successes. Yet many of today's most popular languages were designed by people who hadn't done their homework.<br />
<br />
Haskell was designed by people who knew what they were doing. It's not perfect, but the contrast to an amateur's design is striking.<br />
<br />
== Do I need to know advanced math in order to use Haskell? ==<br />
<br />
No. Certain concepts in Haskell are named after concepts in advanced math. But other languages also appropriate math terminology: consider &quot;[http://en.wikipedia.org/wiki/Singleton_pattern singleton]&quot;, not to mention &quot;function&quot; and &quot;variable&quot;. The way these programming concepts relate to actual mathematics is not necessarily important or relevant.<br />
<br />
In addition, some people write articles about advanced math, using Haskell syntax as their notation. These articles are interesting, but the connection to everyday programming work is usually remote.<br />
<br />
Knowing advanced math will enrich your experience using Haskell, but is by no means a prerequisite.<br />
<br />
= Types =<br />
<br />
== Doesn't a static type system just make it harder to write programs? ==<br />
<br />
Yes. In particular, it makes it ''much'' harder to write ''incorrect'' programs.<br />
<br />
The tradeoff is that correct programs also become somewhat harder to write. In Haskell, features like type inference mitigate this burden to a large extent.<br />
<br />
== How do I make a list with elements of different types? ==<br />
<br />
Are you sure that's what you want? Consider instead creating a single data type to encompass the alternatives:<br />
<br />
<pre class="sourceCode literate haskell">data Identifier<br />
= ByNumber Int<br />
| ByName String<br />
<br />
doStuff :: [Identifier] -&gt; Whatever</pre><br />
In many dynamically-typed languages you aren't allowed to create &quot;variant types&quot; like this. The type system itself is used as a single ad-hoc global variant type. Keep this in mind if you're translating designs from a dynamically-typed language to Haskell.<br />
<br />
== No really, how do I make a list of elements of different types? ==<br />
<br />
Well, you can't avoid putting all your values into one type. But sometimes the &quot;variant type&quot; approach above is too restrictive. Maybe you need to let other people add to the set of allowed types, the way [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html Control.Exception] allows users to define new exception types.<br />
<br />
You can use an existential type, possibly with a type class. Or you can use [http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base/Data-Dynamic.html Data.Dynamic].<br />
<br />
== I'm making an RPG. Should I define a type for each kind of monster, and a type class for them? ==<br />
<br />
Probably not. Some languages require a new type for each new behavior. In Haskell, behaviors are functions or IO actions, which are first-class values. So you can store behaviors in an ordinary data type:<br />
<br />
<pre class="sourceCode literate haskell">data MonsterOps = MonsterOps<br />
{ new :: Monster<br />
, move :: Monster -&gt; Monster<br />
, attack :: Monster -&gt; Player -&gt; Player }<br />
<br />
data Monster = Monster<br />
{ position :: (Int, Int)<br />
, hitpoints :: Double }<br />
<br />
beholder :: MonsterOps<br />
beholder = MonsterOps new move attack where<br />
new = Monster (0,0) 9000<br />
move self = ...<br />
attack self player = ...</pre><br />
This approach is especially nice if you want to generate or transform behaviors on the fly. See the article [http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ &quot;Haskell Antipattern: Existential Typeclass&quot;] for a longer discussion.<br />
<br />
== What's the difference between <tt>Integer</tt> and <tt>Int</tt>? ==<br />
<br />
<tt>Integer</tt> can represent arbitrarily large integers, up to using all of the storage on your machine.<br />
<br />
<tt>Int</tt> can only represent integers in a finite range. The [http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#dx13-135009 language standard] only guarantees a range of -2<sup>29</sup> to (2<sup>29</sup> - 1). Most implementations will provide a full machine-size signed integer, i.e. 32 or 64 bits.<br />
<br />
Operations on <tt>Int</tt> can be much faster than operations on <tt>Integer</tt>, but overflow and underflow can cause weird bugs. Using <tt>Int</tt> in an initial design could be considered premature optimization. Unfortunately, many standard library functions (e.g. <tt>length</tt>, <tt>take</tt>) use <tt>Int</tt>.<br />
<br />
== How do I convert type <tt>A</tt> to type <tt>B</tt>? ==<br />
<br />
This is just another way of asking for a function of type <tt>A -&gt; B</tt>. For example, you can convert <tt>Double</tt> to <tt>Int</tt> with <tt>round</tt>, <tt>ceil</tt>, or <tt>floor</tt>. Haskell does not privilege one of these as ''the'' conversion.<br />
<br />
== Does Haskell have type casts? ==<br />
<br />
The word &quot;cast&quot; can mean a lot of different things.<br />
<br />
* You want to convert a value from one type to another, preserving some idea of what it means. For example, you might convert an <tt>Int</tt> to a <tt>Double</tt> which represents the same integer. In this case you'd just use a function of type <tt>Int -&gt; Double</tt>, such as <tt>fromIntegral</tt>. Haskell doesn't provide special rules or syntax for these functions. See also the previous question.<br />
* You want to pass a value of more specific type to a function expecting a less specific type. There's no syntax for this in Haskell; you just do it. For example you can pass <tt>x :: Int</tt> to <tt>show :: (Show a) =&gt; a -&gt; String</tt>, which automatically specializes the type of <tt>show</tt> to <tt>Int -&gt; String</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, with a checkable runtime error if they do not match. This is rarely the right way to do things in Haskell, and probably indicates a conceptual / design problem instead. If you really do need such a cast, you can use [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html#v:cast <tt>cast</tt>] from [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html Data.Typeable]. In this case the &quot;checkable runtime error&quot; is <tt>cast</tt> returning <tt>Nothing</tt>. Note that Haskell does not have subtyping, so this only happens in the context of instantiating type variables.<br />
* You want to use a value of less specific type under the assumption of a more specific type, and if the assumption is incorrect, the program is allowed to segfault / silently corrupt data / give the attacker a root shell / send illicit photos to your boss. Also known as &quot;C cast&quot;. GHC Haskell has a way to do this, but I dare not speak its name. It's so dangerous and so unlikely to be what you want that it has no place in a general FAQ. You can ask on IRC or read the docs if you have the right kind of morbid curiosity.<br />
<br />
== How do I convert from one numeric type to another? ==<br />
<br />
Probably using one of these:<br />
<br />
<pre class="sourceCode literate haskell">fromIntegral :: (Integral a, Num b ) =&gt; a -&gt; b<br />
realToFrac :: (Real a, Fractional b) =&gt; a -&gt; b</pre><br />
<tt>fromIntegral</tt> converts to a wider range of types, but <tt>realToFrac</tt> converts from types which aren't integers.<br />
<br />
== How do I convert <tt>Maybe Int</tt> to <tt>Int</tt>? ==<br />
<br />
Use pattern-matching. If <tt>mx :: Maybe Int</tt>:<br />
<br />
<pre class="sourceCode literate haskell">case mx of<br />
Just x -&gt; ...<br />
Nothing -&gt; ...</pre><br />
This forces you to consider the <tt>Nothing</tt> case, and is the main advantage of <tt>Maybe</tt>, compared to adding a <tt>null</tt> value to every type.<br />
<br />
See also the functions [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:maybe <tt>maybe</tt>] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe <tt>fromMaybe</tt>] in the module [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html Data.Maybe].<br />
<br />
''Do not'' use <tt>fromJust</tt>, because passing <tt>Nothing</tt> will crash your program with a supremely unhelpful error message. Even when you want to assume the value is not <tt>Nothing</tt>, you can provide a better error message:<br />
<br />
<pre class="sourceCode literate haskell">let x = fromMaybe (error &quot;custom error message&quot;) mx in ...</pre><br />
== How do I convert <tt>IO Int</tt> to <tt>Int</tt>? ==<br />
<br />
You can't; they represent totally different things. An <tt>Int</tt> is an integer. An <tt>IO Int</tt> is a description of how some IO could be performed, in the future, to produce an integer. The IO hasn't been performed yet, and might never happen or might happen more than once.<br />
<br />
See the Introduction to IO.<br />
<br />
== How do I convert between <tt>String</tt> (or <tt>Text</tt>) and <tt>ByteString</tt>? ==<br />
<br />
<tt>String</tt> represents a sequence of Unicode characters. <tt>ByteString</tt> represents a sequence of bytes. There are many different, incompatible ways to represent Unicode characters as bytes. See [http://www.joelonsoftware.com/articles/Unicode.html this article] if you're fuzzy on the character / byte distinction.<br />
<br />
The module [http://hackage.haskell.org/packages/archive/text/0.11.1.5/doc/html/Data-Text-Encoding.html Data.Text.Encoding] from the <tt>text</tt> package provides functions for common Unicode encodings. For more obscure / legacy encodings, see the [http://hackage.haskell.org/package/text-icu <tt>text-icu</tt>] package.<br />
<br />
== How do I catch the error thrown by <tt>read</tt> on a parse failure? ==<br />
<br />
Don't. Instead use<br />
<br />
<pre class="sourceCode literate haskell">reads :: (Read a) =&gt; String -&gt; [(a, String)]</pre><br />
which returns a list of parses, each with a value and a remaining string. An example:<br />
<br />
<pre class="sourceCode literate haskell">safeRead :: (Read a) =&gt; String -&gt; Maybe a<br />
safeRead x = case reads x of<br />
[(v,&quot;&quot;)] -&gt; Just v<br />
_ -&gt; Nothing</pre><br />
= Making it work =<br />
<br />
== How can I find type errors? ==<br />
<br />
There's no silver bullet, but here are a few useful techniques:<br />
<br />
* Comment out type signatures and see what GHC infers, using <tt>:t</tt> in GHCi.<br />
* Add more type signatures, for example inside <tt>let</tt>. This makes your assumptions clearer, so GHC's error message may better explain how your assumptions are inconsistent.<br />
* Replace some subexpressions with <tt>undefined</tt>, which can assume any type.<br />
<br />
== How can I find bugs that occur at runtime? ==<br />
<br />
With pure functions, correctness is a matter of getting the right output for a given input. If one function gives incorrect results, you test the functions it calls, and so on until the bad code is located. You can perform these tests directly in GHCi, or with the help of a tool like QuickCheck.<br />
<br />
You can trace evaluation using [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html Debug.Trace]. You'll get a printout when the expression is evaluated. Due to lazy evaluation, this might be at an unexpected time. But this property is useful when debugging problems related to excessive laziness.<br />
<br />
GHCi also implements a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html &quot;simple imperative-style debugger&quot;].<br />
<br />
Haskell is a natural fit for novel [http://ww2.cs.mu.oz.au/~bjpop/buddha/ &quot;declarative debugging&quot; tools] but to our knowledge, no such tool is production-ready.<br />
<br />
== Why do I get an &quot;undefined symbol&quot; linker error when compiling? ==<br />
<br />
If you're using GHC 6, you should pass <tt>--make</tt> so that GHC will automatically link the appropriate Haskell libraries.<br />
<br />
== How can I get a stack backtrace when my program throws an exception? ==<br />
<br />
The standard stack in GHC Haskell doesn't represent nested function calls. The more informative stack is the profiling cost-center stack, which only exists if your code is built for profiling.<br />
<br />
With GHC 7 you can do something like this:<br />
<br />
<pre>$ ghc -fforce-recomp -prof -auto-all -rtsopts foo.hs</pre><br />
For GHC 6 you should leave off <tt>-rtsopts</tt>, and you'll probably want <tt>--make</tt>.<br />
<br />
You can then run your program with the [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging <tt>-xc</tt> RTS option`]:<br />
<br />
<pre>$ ./foo +RTS -xc</pre><br />
== How can I do automated unit testing? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/testing-and-quality-assurance.html testing chapter] in ''Real World Haskell''.<br />
<br />
== How can I find and fix performance problems? ==<br />
<br />
See the [http://book.realworldhaskell.org/read/profiling-and-optimization.html profiling and optimization chapter] in ''Real World Haskell''.<br />
<br />
= The M-word =<br />
<br />
See also &quot;What monads are not&quot;.<br />
<br />
== I heard Haskell is about monads. I heard that the core feature of Haskell is monads. Is that true? ==<br />
<br />
Absolutely not.<br />
<br />
== I heard monads are like burritos or space suits full of nuclear waste. Is that true? ==<br />
<br />
These analogies are not helpful. See [http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ &quot;Abstraction, intuition, and the 'monad tutorial fallacy&quot;'].<br />
<br />
== I can use monads but I feel like I still don't &quot;get&quot; them. What am I missing? ==<br />
<br />
You're not necessarily missing anything. &quot;<tt>Monad</tt>&quot; is just the name of a generic API that applies to many different types. The types implementing the <tt>Monad</tt> API don't have a lot in common.<br />
<br />
You might want to read &quot;Typeclassopedia&quot; to see how <tt>Monad</tt> fits in with other similar APIs.<br />
<br />
== Do I need to understand monads in order to do IO? ==<br />
<br />
Not really. &quot;<tt>Monad</tt>&quot; is the name of a generic API that applies to many different types, including the <tt>IO</tt> type. If you're only thinking about IO, you don't need to worry about how this API generalizes.<br />
<br />
See the Introduction to IO.<br />
<br />
== What's the difference between <tt>State</tt> and <tt>ST</tt> monads? ==<br />
<br />
<tt>State s a</tt> is just a wrapper for the function type <tt>s -&gt; (a, s)</tt>: a function that takes an &quot;old state&quot; and returns a &quot;new state&quot; along with its result. You can implement <tt>State</tt> in a few lines of standard Haskell, without any special help from the compiler.<br />
<br />
<tt>ST</tt> gives you true mutable variables with in-place update. You can't implement it yourself in standard Haskell. In GHC, <tt>STRef</tt> and <tt>IORef</tt> will behave the same way at runtime. The difference is the extra compile-time safety checking associated with <tt>runST</tt>.</div>Keegan