https://wiki.haskell.org/api.php?action=feedcontributions&user=Lemming&feedformat=atomHaskellWiki - User contributions [en]2021-08-03T05:47:06ZUser contributionsMediaWiki 1.27.4https://wiki.haskell.org/index.php?title=LLVM&diff=63448LLVM2020-10-02T11:22:59Z<p>Lemming: fixed nested list</p>
<hr />
<div>[http://llvm.org/ LLVM] is an abbreviation of "Low Level Virtual Machine"; LLVM is:<br />
* A compilation strategy <br />
* A virtual instruction set<br />
* A compiler infrastructure<br />
<br />
It is developed by the University of Illinois.<br />
It is implemented on many platforms, amongst others the [http://www.ipodobserver.com/story/30184 iPhone].<br />
<br />
You can use this from a Haskell program using essentially two bindings:<br />
<br />
A strongly typed interface that is mainly intended to accelerate your Haskell programs with low-level code:<br />
* {{HackagePackage|id=llvm-tf}}, {{HackagePackage|id=llvm-ffi}}<br />
* a [http://hub.darcs.net/thielema/llvm-ffi/ darcs repository],<br />
* a [http://augustss.blogspot.com/2009/01/llvm-llvm-low-level-virtual-machine-is.html blog article] with examples,<br />
* the article "[http://augustss.blogspot.com/2009/01/performance-update-ive-continued.html A performance update]" that describes, how LLVM can improve performance<br />
* {{HackagePackage|id=llvm-extra}} provides high-level control structures (<hask>ifThenElse</hask>, <hask>whileLoop</hask>, <hask>Maybe</hask>), vector instructions, automatic adaption to target specific extensions<br />
* {{HackagePackage|id=knead}} provides array processing similar to {{HackagePackage|id=accelerate}}<br />
* Example applications:<br />
** {{HackagePackage|id=synthesizer-llvm}} provides efficient signal processing using vector instructions, including a live [[Synthesizer|software synthesizer]]<br />
** {{HackagePackage|id=patch-image}} constructs a big image from overlapping parts<br />
<br />
An untyped interface mainly intended to write compilers and analyse LLVM bitcode:<br />
* {{HackagePackage|id=llvm-hs}}<br />
<br />
[[Category:Packages]]<br />
[[Category:Performance]]<br />
[[Category:Compiler tools]]</div>Lemminghttps://wiki.haskell.org/index.php?title=LLVM&diff=63447LLVM2020-10-02T10:11:25Z<p>Lemming: updated to year 2020</p>
<hr />
<div>[http://llvm.org/ LLVM] is an abbreviation of "Low Level Virtual Machine"; LLVM is:<br />
* A compilation strategy <br />
* A virtual instruction set<br />
* A compiler infrastructure<br />
<br />
It is developed by the University of Illinois.<br />
It is implemented on many platforms, amongst others the [http://www.ipodobserver.com/story/30184 iPhone].<br />
<br />
You can use this from a Haskell program using essentially two bindings:<br />
<br />
A strongly typed interface that is mainly intended to accelerate your Haskell programs with low-level code:<br />
* {{HackagePackage|id=llvm-tf}}, {{HackagePackage|id=llvm-ffi}}<br />
* a [http://hub.darcs.net/thielema/llvm-ffi/ darcs repository],<br />
* a [http://augustss.blogspot.com/2009/01/llvm-llvm-low-level-virtual-machine-is.html blog article] with examples,<br />
* the article "[http://augustss.blogspot.com/2009/01/performance-update-ive-continued.html A performance update]" that describes, how LLVM can improve performance<br />
* {{HackagePackage|id=llvm-extra}} provides high-level control structures (<hask>ifThenElse</hask>, <hask>whileLoop</hask>, <hask>Maybe</hask>), vector instructions, automatic adaption to target specific extensions<br />
* {{HackagePackage|id=knead}} provides array processing similar to {{HackagePackage|id=accelerate}}<br />
* Example applications:<br />
- {{HackagePackage|id=synthesizer-llvm}} provides efficient signal processing using vector instructions, including a live [[Synthesizer|software synthesizer]]<br />
- {{HackagePackage|id=patch-image}} constructs a big image from overlapping parts<br />
<br />
An untyped interface mainly intended to write compilers and analyse LLVM bitcode:<br />
* {{HackagePackage|id=llvm-hs}}<br />
<br />
[[Category:Packages]]<br />
[[Category:Performance]]<br />
[[Category:Compiler tools]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Live-Sequencer&diff=62622Live-Sequencer2018-09-26T09:50:15Z<p>Lemming: update URLs</p>
<hr />
<div>Live-Sequencer does the following:<br />
An editor shows a textual description of music (like [[Haskore]]),<br />
an interpreter computes and emits a stream of [[MIDI]] events via [[ALSA]].<br />
While doing so it highlights active terms and shows the result of the term reductions.<br />
The nice thing is, that the user can change the program while it is performed.<br />
Additionally modules can be altered via a web interface.<br />
This way several people can take part in the composition.<br />
However they need to have video and audio access to the running sequencer<br />
in order to see and hear how their parts fit into the overall composition.<br />
<br />
We address two applications:<br />
* interactive multi-user programmed music composition<br />
* education of how functional programs are interpreted<br />
<br />
== Resources ==<br />
<br />
* Installation from Hackage: {{HackagePackage|id=live-sequencer}}<br />
* Henning's Darcs repository with the cutting edge features:<br />
** darcs get https://hub.darcs.net/thielema/livesequencer<br />
* some example songs:<br />
** https://hub.darcs.net/thielema/livesequencer-example<br />
* Old Bug-Tracker: http://dfa.imn.htwk-leipzig.de/bugzilla/describecomponents.cgi?product=live-sequencer<br />
* Johannes' Git repository - the old git repository:<br />
** Direct access: <code>git clone git://dfa.imn.htwk-leipzig.de/srv/git/seq/</code><br />
** Web frontend: http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=seq.git;a=tree<br />
<br />
== Papers ==<br />
<br />
* Henning Thielemann: [http://arxiv.org/abs/1202.4269 Live-Musikprogrammierung in Haskell], Arbeitstagung Programmiersprachen ATPS 2012 (German)<br />
* Henning Thielemann: [http://arxiv.org/abs/1303.5768 Live music programming in Haskell], Linux Audio Conference LAC 2013<br />
<br />
== Demonstrations ==<br />
<br />
* [http://www.youtube.com/watch?v=88jK162l6mE kling klong]<br />
* [http://www.youtube.com/watch?v=sXywCHR9WwE electronical menu]<br />
* [http://www.youtube.com/watch?v=-fmxHM69zgI Tausend Sterne sind ein Dom] (engl. "Thousand stars are a cathedral")<br />
* [http://www.youtube.com/watch?v=O5k0wUh0lj8 Glorious Kingdom] (Gospel)<br />
* [http://www.youtube.com/watch?v=0EQCgi5qa3E Alta trinita beata] (featuring speech synthesis)<br />
* [http://www.youtube.com/watch?v=Sk-NtRYqVy4 Drei Chinesen mit dem Kontrabass] (featuring speech synthesis)<br />
<br />
[[Category:Music]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Battleship_game_combinatorics&diff=62290Battleship game combinatorics2018-01-19T20:47:22Z<p>Lemming: update URL of Haskell code to hub.darcs.net</p>
<hr />
<div>This page is a table, reporting the number of ways to place ships as in the game "battleship". The table assumes that ships cannot be placed adjacent to one another, though not all versions of the game use this rule.<br />
<br />
{| class="wikitable" style="text-align: right"<br />
|-<br />
! colspan="4" | Ship sizes<br />
! rowspan="2" | Number of configurations <br> on a 10×10 board<br />
|-<br />
! 2<br />
! 3<br />
! 4<br />
! 5<br />
|-<br />
| || || || || 1<br />
|-<br />
| 1 || || || || 180<br />
|-<br />
| 2 || || || || 13952<br />
|-<br />
| 3 || || || || 614372<br />
|-<br />
| 4 || || || || 17086631<br />
|-<br />
| || 1 || || || 160<br />
|-<br />
| 1 || 1 || || || 23864<br />
|-<br />
| 2 || 1 || || || 1512096<br />
|-<br />
| 3 || 1 || || || 53606768<br />
|-<br />
| 4 || 1 || || || 1179864432<br />
|-<br />
| || 2 || || || 10124<br />
|-<br />
| 1 || 2 || || || 1230092<br />
|-<br />
| 2 || 2 || || || 62495628<br />
|-<br />
| 3 || 2 || || || 1745117572<br />
|-<br />
| 4 || 2 || || || 29650630088<br />
|-<br />
| || 3 || || || 330840<br />
|-<br />
| 1 || 3 || || || 32094960<br />
|-<br />
| 2 || 3 || || || 1278079616<br />
|-<br />
| 3 || 3 || || || 27395120928<br />
|-<br />
| 4 || 3 || || || 348892008792<br />
|-<br />
| || || 1 || || 140<br />
|-<br />
| 1 || || 1 || || 20072<br />
|-<br />
| 2 || || 1 || || 1219008<br />
|-<br />
| 3 || || 1 || || 41283320<br />
|-<br />
| 4 || || 1 || || 864647388<br />
|-<br />
| || 1 || 1 || || 16896<br />
|-<br />
| 1 || 1 || 1 || || 1966664<br />
|-<br />
| 2 || 1 || 1 || || 95386968<br />
|-<br />
| 3 || 1 || 1 || || 2532545416<br />
|-<br />
| 4 || 1 || 1 || || 40721312760<br />
|-<br />
| || 2 || 1 || || 786968<br />
|-<br />
| 1 || 2 || 1 || || 72831964<br />
|-<br />
| 2 || 2 || 1 || || 2755256320<br />
|-<br />
| 3 || 2 || 1 || || 55828223540<br />
|-<br />
| 4 || 2 || 1 || || 668256987440<br />
|-<br />
| || 3 || 1 || || 18382184<br />
|-<br />
| 1 || 3 || 1 || || 1320017704<br />
|-<br />
| 2 || 3 || 1 || || 37880082192<br />
|-<br />
| 3 || 3 || 1 || || 567343768064<br />
|-<br />
| 4 || 3 || 1 || || 4871721743520<br />
|-<br />
| || || 2 || || 6996<br />
|-<br />
| 1 || || 2 || || 779752<br />
|-<br />
| 2 || || 2 || || 36085692<br />
|-<br />
| 3 || || 2 || || 910464972<br />
|-<br />
| 4 || || 2 || || 13847185918<br />
|-<br />
| || 1 || 2 || || 619136<br />
|-<br />
| 1 || 1 || 2 || || 54625952<br />
|-<br />
| 2 || 1 || 2 || || 1961767760<br />
|-<br />
| 3 || 1 || 2 || || 37549258992<br />
|-<br />
| 4 || 1 || 2 || || 422118615240<br />
|-<br />
| || 2 || 2 || || 20505284<br />
|-<br />
| 1 || 2 || 2 || || 1396400720<br />
|-<br />
| 2 || 2 || 2 || || 37804399592<br />
|-<br />
| 3 || 2 || 2 || || 530879625444<br />
|-<br />
| 4 || 2 || 2 || || 4242772005768<br />
|-<br />
| || 3 || 2 || || 328511112<br />
|-<br />
| 1 || 3 || 2 || || 16757986408<br />
|-<br />
| 2 || 3 || 2 || || 330360758520<br />
|-<br />
| 3 || 3 || 2 || || 3268821509016<br />
|-<br />
| 4 || 3 || 2 || || 17707810153184<br />
|-<br />
| || || || 1 || 120<br />
|-<br />
| 1 || || || 1 || 16528<br />
|-<br />
| 2 || || || 1 || 961464<br />
|-<br />
| 3 || || || 1 || 31086744<br />
|-<br />
| 4 || || || 1 || 619268128<br />
|-<br />
| || 1 || || 1 || 13808<br />
|-<br />
| 1 || 1 || || 1 || 1538520<br />
|-<br />
| 2 || 1 || || 1 || 71194112<br />
|-<br />
| 3 || 1 || || 1 || 1796509352<br />
|-<br />
| 4 || 1 || || 1 || 27329683408<br />
|-<br />
| || 2 || || 1 || 610688<br />
|-<br />
| 1 || 2 || || 1 || 53879808<br />
|-<br />
| 2 || 2 || || 1 || 1935562696<br />
|-<br />
| 3 || 2 || || 1 || 37068246456<br />
|-<br />
| 4 || 2 || || 1 || 417017581256<br />
|-<br />
| || 3 || || 1 || 13477504<br />
|-<br />
| 1 || 3 || || 1 || 918108728<br />
|-<br />
| 2 || 3 || || 1 || 24872048856<br />
|-<br />
| 3 || 3 || || 1 || 349608204104<br />
|-<br />
| 4 || 3 || || 1 || 2797606827136<br />
|-<br />
| || || 1 || 1 || 11360<br />
|-<br />
| 1 || || 1 || 1 || 1211008<br />
|-<br />
| 2 || || 1 || 1 || 53413832<br />
|-<br />
| 3 || || 1 || 1 || 1279310984<br />
|-<br />
| 4 || || 1 || 1 || 18385007248<br />
|-<br />
| || 1 || 1 || 1 || 954544<br />
|-<br />
| 1 || 1 || 1 || 1 || 80194520<br />
|-<br />
| 2 || 1 || 1 || 1 || 2731237000<br />
|-<br />
| 3 || 1 || 1 || 1 || 49341382288<br />
|-<br />
| 4 || 1 || 1 || 1 || 520599890368<br />
|-<br />
| || 2 || 1 || 1 || 29852632<br />
|-<br />
| 1 || 2 || 1 || 1 || 1925751392<br />
|-<br />
| 2 || 2 || 1 || 1 || 49143133528<br />
|-<br />
| 3 || 2 || 1 || 1 || 646677411848<br />
|-<br />
| 4 || 2 || 1 || 1 || 4808897160408<br />
|-<br />
| || 3 || 1 || 1 || 448574416<br />
|-<br />
| 1 || 3 || 1 || 1 || 21536631136<br />
|-<br />
| 2 || 3 || 1 || 1 || 397108468832<br />
|-<br />
| 3 || 3 || 1 || 1 || 3647432090016<br />
|-<br />
| 4 || 3 || 1 || 1 || 18170989432520<br />
|-<br />
| || || 2 || 1 || 371048<br />
|-<br />
| 1 || || 2 || 1 || 29660864<br />
|-<br />
| 2 || || 2 || 1 || 957045912<br />
|-<br />
| 3 || || 2 || 1 || 16298373712<br />
|-<br />
| 4 || || 2 || 1 || 161138941144<br />
|-<br />
| || 1 || 2 || 1 || 21906376<br />
|-<br />
| 1 || 1 || 2 || 1 || 1337029984<br />
|-<br />
| 2 || 1 || 2 || 1 || 32111473656<br />
|-<br />
| 3 || 1 || 2 || 1 || 395146057864<br />
|-<br />
| 4 || 1 || 2 || 1 || 2726362307664<br />
|-<br />
| || 2 || 2 || 1 || 462924032<br />
|-<br />
| 1 || 2 || 2 || 1 || 20886349672<br />
|-<br />
| 2 || 2 || 2 || 1 || 359461539224<br />
|-<br />
| 3 || 2 || 2 || 1 || 3056118386176<br />
|-<br />
| 4 || 2 || 2 || 1 || 13949906853080<br />
|-<br />
| || 3 || 2 || 1 || 4488051160<br />
|-<br />
| 1 || 3 || 2 || 1 || 143891605904<br />
|-<br />
| 2 || 3 || 2 || 1 || 1693472099056<br />
|-<br />
| 3 || 3 || 2 || 1 || 9404689335808<br />
|-<br />
| 4 || 3 || 2 || 1 || 26509655816984<br />
|}<br />
<br />
== References ==<br />
<br />
* [https://hub.darcs.net/thielema/battleship-combinatorics/browse/src/Combinatorics/Battleship/Count/ShortenShip.hs Haskell program] that computes the table<br />
<br />
[[Category:Combinatorics]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Monomorphism&diff=61815Monomorphism2017-05-21T20:01:58Z<p>Lemming: revert spam by TaalbOclim and TabocRelde</p>
<hr />
<div>[[Category:Glossary]]<br />
<br />
Monomorphism is the opposite of [[polymorphism]]. That is, a function is polymorphic if it works for several different types - and thus, a function is ''monomorphic'' if it works only for ''one'' type.<br />
<br />
As an example, <hask>map</hask> is polymorphic. It's type is simply<br />
<br />
<haskell><br />
map :: (a -> b) -> [a] -> [b]<br />
</haskell><br />
<br />
However, the function<br />
<br />
<haskell><br />
foo :: (Int -> Int) -> [Int] -> [Int]<br />
foo = map<br />
</haskell><br />
<br />
performs an identical operation to <hask>map</hask> (as is evident from the second line), but has a monomorphic type; it will ''only'' accept lists of <hask>Int</hask> and functions over them.<br />
<br />
Perhaps you were looking for [[monomorphism restriction]]?</div>Lemminghttps://wiki.haskell.org/index.php?title=Nonogram&diff=60484Nonogram2016-01-04T11:55:14Z<p>Lemming: /* Set based solver */ solution based on exact set cover</p>
<hr />
<div>[[Category:Code]]<br />
Here are some solvers for Nonogram puzzles. A description of what a nonogram is can be found in [[99_questions/95_to_99#Problem_98|Ninety-Nine Haskell Problems]].<br />
<br />
== Backtracking solver ==<br />
<br />
The first solution is a simple backtracking algorithm, but is quite slow for larger problems.<br />
<haskell><br />
data Square = Blank | Cross deriving (Eq)<br />
instance Show Square where<br />
show Blank = " "<br />
show Cross = "X"<br />
<br />
-- create all possibilities of arranging the given blocks in a line of "n" elements<br />
rows n [] = [replicate n Blank]<br />
rows n (k:ks) | n < k = []<br />
rows n (k:ks) = <br />
[Blank : row | row <- rows (n-1) (k:ks)] ++<br />
if null ks then [replicate k Cross ++ replicate (n-k) Blank]<br />
else [replicate k Cross ++ Blank : row | row <- rows (n-k-1) ks]<br />
<br />
-- contract a given line into the block format<br />
-- i.e. contract [Cross,Blank,Cross] == [1,1]<br />
contract = map length . filter (\(x:_) -> x==Cross) . group<br />
<br />
-- create all solutions by combining all possible rows in all possible ways<br />
-- then pick a solution and check whether its block signature fits<br />
solver horz vert = filter fitsVert possSolution<br />
where possSolution = mapM (rows (length vert)) horz<br />
fitsVert rs = map contract (transpose rs) == vert<br />
<br />
-- output the (first) solution<br />
nonogram horz vert = printSolution $ head $ solver horz vert<br />
where printSolution = putStr . unlines . map (concatMap show) . transpose<br />
</haskell><br />
<br />
This is a solution done for simplicity rather than performance. It's SLOOOOW. If I were to check intermediate solutions against the blocks that should come out instead of sequencing everything, the List monad would fail much earlier...<br />
<br />
It builds all combinations of blocks in a row (stolen from solution 2 :) and then builds all combinations of rows. The resulting columns are then contracted into the short block block form and the signature compared to the target.<br />
<br />
== Deducing solver ==<br />
<br />
We can make the search much faster (but more obscure) by deducing the values of as many squares as possible before guessing, as in this solution:<br />
<haskell><br />
module Nonogram where<br />
<br />
import Control.Monad<br />
import Data.List<br />
import Data.Maybe<br />
<br />
type Row s = [s]<br />
type Grid s = [Row s]<br />
<br />
-- partial information about a square<br />
type Square = Maybe Bool<br />
<br />
-- Print the first solution (if any) to the nonogram<br />
nonogram :: [[Int]] -> [[Int]] -> String<br />
nonogram rs cs = case solve rs cs of<br />
[] -> "Inconsistent\n"<br />
(grid:_) -> showGrid rs cs grid<br />
<br />
-- All solutions to the nonogram<br />
solve :: [[Int]] -> [[Int]] -> [Grid Bool]<br />
solve rs cs = [grid' |<br />
-- deduce as many squares as we can<br />
grid <- maybeToList (deduction rs cs),<br />
-- guess the rest, governed by rs<br />
grid' <- zipWithM (rowsMatching nc) rs grid,<br />
-- check each guess against cs<br />
map contract (transpose grid') == cs]<br />
where nc = length cs<br />
contract = map length . filter head . group<br />
<br />
-- A nonogram with all the values we can deduce<br />
deduction :: [[Int]] -> [[Int]] -> Maybe (Grid Square)<br />
deduction rs cs = converge step init<br />
where nr = length rs<br />
nc = length cs<br />
init = replicate nr (replicate nc Nothing)<br />
step = (improve nc rs . transpose) <.> (improve nr cs . transpose)<br />
improve n = zipWithM (common n)<br />
(g <.> f) x = f x >>= g<br />
<br />
-- repeatedly apply f until a fixed point is reached<br />
converge :: (Monad m, Eq a) => (a -> m a) -> a -> m a<br />
converge f s = do<br />
s' <- f s<br />
if s' == s then return s else converge f s'<br />
<br />
-- common n ks partial = commonality between all possible ways of<br />
-- placing blocks of length ks in a row of length n that match partial.<br />
common :: Int -> [Int] -> Row Square -> Maybe (Row Square)<br />
common n ks partial = case rowsMatching n ks partial of<br />
[] -> Nothing<br />
rs -> Just (foldr1 (zipWith unify) (map (map Just) rs))<br />
where unify :: Square -> Square -> Square<br />
unify x y<br />
| x == y = x<br />
| otherwise = Nothing<br />
<br />
-- rowsMatching n ks partial = all possible ways of placing blocks of<br />
-- length ks in a row of length n that match partial.<br />
rowsMatching :: Int -> [Int] -> Row Square -> [Row Bool]<br />
rowsMatching n [] [] = [[]]<br />
rowsMatching n ks [] = []<br />
rowsMatching n ks (Nothing:partial) =<br />
rowsMatchingAux n ks True partial ++<br />
rowsMatchingAux n ks False partial<br />
rowsMatching n ks (Just s:partial) = <br />
rowsMatchingAux n ks s partial<br />
<br />
rowsMatchingAux :: Int -> [Int] -> Bool -> Row Square -> [Row Bool]<br />
rowsMatchingAux n ks False partial =<br />
[False : row | row <- rowsMatching (n-1) ks partial]<br />
rowsMatchingAux n [k] True partial =<br />
[replicate k True ++ replicate (n-k) False |<br />
n >= k && all (/= Just False) front && all (/= Just True) back]<br />
where (front, back) = splitAt (k-1) partial<br />
rowsMatchingAux n (k:ks) True partial =<br />
[replicate k True ++ False : row |<br />
n > k+1 && all (/= Just False) front && blank /= Just True,<br />
row <- rowsMatching (n-k-1) ks partial']<br />
where (front, blank:partial') = splitAt (k-1) partial<br />
<br />
showGrid :: [[Int]] -> [[Int]] -> Grid Bool -> String<br />
showGrid rs cs ss = unlines (zipWith showRow rs ss ++ showCols cs)<br />
where showRow rs ss = concat [['|', cellChar s] | s <- ss] ++ "| " ++<br />
unwords (map show rs)<br />
showCols cs<br />
| all null cs = []<br />
| otherwise = concatMap showCol cs : showCols (map advance cs)<br />
showCol (k:_)<br />
| k < 10 = ' ':show k<br />
| otherwise = show k<br />
showCol [] = " "<br />
cellChar True = 'X'<br />
cellChar False = '_'<br />
advance [] = []<br />
advance (x:xs) = xs<br />
</haskell><br />
We build up knowledge of which squares must be filled and which must be blank, until we can't make any more deductions.<br />
Some puzzles cannot be completely solved in this way, so then we guess values by the same method as the first solution for any remaining squares.<br />
<br />
== Set based solver ==<br />
By: Twan van Laarhoven<br />
<br />
The idea behind this solver is similair to that of most [[Sudoku]] solvers, in each cell a set of its possible values are stored, and these sets are iterativly reduced until a single value remains. Instead of only using the possible values black and white this solver uses positions. If for some row the lengths [4,3] are given, then there are 10 possible positions: <br />
* white, left of both sections of black<br />
* 4 positions inside the first black section.<br />
* between the two black sections<br />
* 3 positions inside the second black section.<br />
* after both sections.<br />
Each cell has a both a horizontal and a vertical set of possible positions/values.<br />
<br />
There are two kinds of passes that are made:<br />
* hStep: for each cell, it can only have values that can follow that of its left neighbour.<br />
* efStep: If a cell is guaranteed to be white/black according to its horizontal value its vertical value must also be white/black, and vice-versa.<br />
The hStep is applied in all four directions by reversing and transposing the board.<br />
<br />
If no more progress can be made using this algorithm, the solver makes a guess. In the first cell that still has multiple choices all these choices are inspected individually by 'splitting' the puzzle into a list of puzzles. These are then solved using the deterministic algorithm. Puzzles that lead to a contradiction (no possible values in a cell) are removed from the list.<br />
<br />
<haskell><br />
module Nonogram where<br />
<br />
import qualified Data.Set as Set<br />
import Data.Set (Set)<br />
import qualified Data.Map as Map<br />
import Data.Map (Map)<br />
import Data.List<br />
<br />
------------------------------------------------------------------------<br />
-- Cells<br />
<br />
-- | The value of a single cell<br />
newtype Value = Value Int<br />
deriving (Eq, Ord, Show)<br />
<br />
-- | Negative values encode empty cells, positive values filled cells<br />
empty (Value n) = n <= 0<br />
full = not . empty<br />
<br />
type Choice = Set Value<br />
<br />
------------------------------------------------------------------------<br />
-- Puzzle<br />
<br />
type Grid = [[Choice]]<br />
<br />
-- | Datatype for solved and unsolved puzzles<br />
data Puzzle = Puzzle<br />
-- | List of rows, containing horizontal choices for each cell<br />
{ gridH :: Grid<br />
-- | List of columns, containing vertical choices for each cell<br />
, gridV :: Grid<br />
-- | What is allowed before/after a specific value?<br />
-- (after (Value 0)) are the values allowed on the first position<br />
, afterH, beforeH :: [Value -> Choice]<br />
, afterV, beforeV :: [Value -> Choice]<br />
}<br />
<br />
instance Eq Puzzle where<br />
p == q = gridH p == gridH q<br />
<br />
instance Show Puzzle where<br />
show = dispGrid . gridH<br />
<br />
-- | Transpose a puzzle (swap horizontal and vertical components)<br />
transposeP :: Puzzle -> Puzzle<br />
transposeP p = Puzzle<br />
{ gridH = gridV p<br />
, gridV = gridH p<br />
, afterH = afterV p<br />
, beforeH = beforeV p<br />
, afterV = afterH p<br />
, beforeV = beforeH p<br />
}<br />
<br />
-- | Display a puzzle<br />
dispGrid = concatMap (\r -> "[" ++ map disp'' r ++ "]\n")<br />
where disp'' x<br />
| Set.null x = 'E'<br />
| setAll full x = '#'<br />
| setAll empty x = '.'<br />
| otherwise = '/'<br />
<br />
------------------------------------------------------------------------<br />
-- Making puzzles<br />
<br />
-- | Make a puzzle, when given the numbers at the edges<br />
puzzle :: [[Int]] -> [[Int]] -> Puzzle<br />
puzzle h v = Puzzle<br />
{ gridH = map (replicate cols . Set.fromList) ordersH<br />
, gridV = map (replicate rows . Set.fromList) ordersV<br />
, afterH = map mkAfter ordersH<br />
, beforeH = map mkAfter (map reverse ordersH)<br />
, afterV = map mkAfter ordersV<br />
, beforeV = map mkAfter (map reverse ordersV)<br />
}<br />
where rows = length h<br />
cols = length v<br />
ordersH = map order h<br />
ordersV = map order v<br />
<br />
-- | Order of allowed values in a single row/column<br />
-- Input = list of lengths of filled cells, which are separated by empty cells<br />
-- Repeats empty values, because those values may be repeated<br />
-- example:<br />
-- order [1,2,3] = map Value [-1,-1, 1, -2,-2, 2,3, -4,-4, 4,5,6, -7,-7]<br />
order :: [Int] -> [Value]<br />
order = order' 1<br />
where order' n [] = [Value (-n), Value (-n)] -- repeated empty cells allowed at the end<br />
order' n (x:xs) = [Value (-n), Value (-n)] ++ map Value [n..n+x-1] ++ order' (n+x) xs<br />
<br />
-- | What values are allowed after a given value in the given order?<br />
mkAfter :: [Value] -> Value -> Choice<br />
mkAfter order = (mkAfterM order Map.!)<br />
<br />
mkAfterM order = Map.fromListWith (Set.union) aftersL<br />
where aftersL = -- after the start (0) the first non empty value, at position 2 is allowed<br />
-- this is a bit of a hack<br />
(if length order > 2<br />
then [(Value 0, Set.singleton (order !! 2))]<br />
else []) ++<br />
-- after each value comes the next one in the list<br />
zip (Value 0:order) (map Set.singleton order)<br />
<br />
------------------------------------------------------------------------<br />
-- Classifying puzzles<br />
<br />
-- | Is a puzzle completely solved?<br />
done :: Puzzle -> Bool<br />
done = all (all ((==1) . Set.size)) . gridH<br />
<br />
-- | Is a puzzle invalid?<br />
invalid :: Puzzle -> Bool<br />
invalid = any (any Set.null) . gridH<br />
<br />
------------------------------------------------------------------------<br />
-- Solving<br />
<br />
-- | Solve a puzzle deterministicly, i.e. don't make any guesses<br />
-- make sure<br />
solveD :: Puzzle -> Puzzle<br />
solveD = takeSame . iterate step<br />
<br />
-- | All solving steps combined, the orientation after a step is the same as before<br />
step = efStep . transposeP . hStep . transposeP . hStep<br />
<br />
-- | A step in the solving process.<br />
-- Propagate allowed values after from left to right<br />
hStep p = p { gridH = gridH'' }<br />
where gridH' = zipWith hStepLTR (afterH p) (gridH p) -- left to right<br />
gridH'' = zipWith hStepRTL (beforeH p) (gridH') -- right to left<br />
<br />
-- | hStep on a single row, from left to right, after is a function that gives the allowed after values<br />
hStepLTR after row = hStepLTR' (after (Value 0)) row<br />
where hStepLTR' _ [] = []<br />
hStepLTR' afterPrev (x:xs) = x' : hStepLTR' afterX' xs<br />
where x' = Set.intersection x afterPrev<br />
afterX' = Set.unions $ map after $ Set.toList x'<br />
-- | Same as hStepRTL, but from right to left, should be given allowed before values<br />
hStepRTL before = reverse . hStepLTR before . reverse<br />
<br />
-- | A step in the solving process<br />
-- Combine horizontal and verticall grids, empty/full in one <-> empty/full in the oter<br />
-- Note: we transpose gridV, to make it compatible with gridH (row-of-cells)<br />
efStep puzzle = puzzle { gridH = gridH', gridV = transpose gridV't }<br />
where (gridH', gridV't) = zzMap ef (gridH puzzle) (transpose (gridV puzzle))<br />
-- Step on a single cell<br />
ef h v = filterCell empty . filterCell full $ (h,v)<br />
-- Step on a single cell, for a single predicate, if either h or v satisfies the predicate<br />
-- then the other is filtered so it will satisfy as well<br />
filterCell pred (h,v) <br />
| setAll pred h = (h, Set.filter pred v)<br />
| setAll pred v = (Set.filter pred h, v)<br />
| otherwise = (h, v)<br />
<br />
------------------------------------------------------------------------<br />
-- Guessing<br />
<br />
-- | Solve a puzzle, gives all solutions<br />
solve :: Puzzle -> [Puzzle]<br />
solve puzzle<br />
| done puzzle' = [puzzle'] -- single solution<br />
| invalid puzzle' = [] -- no solutions<br />
| otherwise = concatMap solve (guess puzzle') -- we have to guess<br />
where puzzle' = solveD puzzle<br />
<br />
-- | Split a puzzle into multiple puzzles, by making a guess at the first position with multiple choices<br />
-- we return all possible puzzles for making a guess at that position<br />
guess :: Puzzle -> [Puzzle]<br />
guess puzzle = map (\gh -> puzzle {gridH = gh} ) gridHs<br />
where gridHs = trySplit (trySplit splitCell) (gridH puzzle)<br />
<br />
-- | Try to split a cell into multiple alternatives<br />
splitCell :: Choice -> [Choice]<br />
splitCell = map Set.singleton . Set.toList<br />
<br />
-- | Try to split a single item in a list using the function f<br />
-- Stops at the first position where f has more than 1 result.<br />
-- TODO: A more soffisticated guessing strategy might be faster.<br />
trySplit :: (a -> [a]) -> [a] -> [[a]]<br />
trySplit f [] = []<br />
trySplit f (x:xs)<br />
| length fx > 1 = map (:xs) fx -- This element is split, don't look further<br />
| length fxs > 1 = map (x:) fxs -- The list is split furter on<br />
| otherwise = []<br />
where fx = f x<br />
fxs = trySplit f xs<br />
<br />
------------------------------------------------------------------------<br />
-- Utilities<br />
<br />
-- | Set.all, similair to Data.List.all<br />
setAll f = all f . Set.toList<br />
<br />
-- | Map a function simultaniously over two lists, like zip<br />
zMap :: (a -> b -> (c, d)) -> [a] -> [b] -> ([c], [d])<br />
zMap f a b = unzip $ zipWith f a b<br />
<br />
-- | Map a function simultaniously over two lists of lists, like zip<br />
zzMap :: (a -> b -> (c, d)) -> [[a]] -> [[b]] -> ([[c]], [[d]])<br />
zzMap f a b = unzip $ zipWith (zMap f) a b<br />
<br />
-- | Find the first item in a list that is repeated<br />
takeSame :: Eq a => [a] -> a<br />
takeSame (a:b:xs)<br />
| a == b = a<br />
| otherwise = takeSame (b:xs)<br />
<br />
------------------------------------------------------------------------<br />
-- Test<br />
</haskell><br />
<br />
Here is a test puzzle that can be used in the solver:<br />
<haskell><br />
-- | A test puzzle<br />
test = puzzle [[6],[3,1,3],[1,3,1,3],[3,14],[1,1,1],<br />
[1,1,2,2],[5,2,2],[5,1,1],[5,3,3,3],[8,3,3,3]]<br />
[[4],[4],[1,5],[3,4],[1,5],[1],[4,1],[2,2,2],<br />
[3,3],[1,1,2],[2,1,1],[1,1,2],[4,1],[1,1,2],<br />
[1,1,1],[2,1,2],[1,1,1],[3,4],[2,2,1],[4,1]]<br />
</haskell><br />
<br />
<br />
== Solver based on exact set cover ==<br />
By Henning Thielemann<br />
<br />
The package {{HackagePackage|id=set-cover}} provides a solver based on a generic set-cover solver.</div>Lemminghttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=60483Applications and libraries/Games2016-01-04T11:51:08Z<p>Lemming: /* Games */ board-games</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;{{HackagePackage|id=babylon}}<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://www.haskell.org/communities/11-2015/html/report.html#sect7.13.5 Barbarossa]<br />
:A UCI chess engine written completely in Haskell<br />
<br />
;{{HackagePackage|id=board-games}}<br />
: Computer player algorithms for three games: Connect Four, Rows&Columns, Mastermind. Intended for running as a web server.<br />
<br />
;{{HackagePackage|id=boomslang}}<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend Defend The King from Forces of Different]<br />
: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]<br />
: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[http://mfuglos.github.io/jeopardy Fuglos Jeopardy]<br />
:Fuglos Jeopardy is a free implementation of a game resembling the popular quiz show 'Jeopardy'. It is written using Gtk2Hs as GUI toolkit. It is quite feature complete and easy to use. It contains support for LaTeX, so you can for example use LaTeX math syntax in your data sheets and thus organize a math jeopoardy event. Licensed under GPL3.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
; [https://github.com/ocharles/hadoom hadoom]<br />
:A clone of Doom, using reactive-banana, GTK, and the "diagrams" library.<br />
<br />
; [https://github.com/ivanperez-keera/haskanoid haskanoid]<br />
:An breakout game with SDL graphics and Kinect and Wiimote support. Written in FRP, there's a fork in Haskell for Android.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII Tetris in Haskell<br />
<br />
;{{HackagePackage|id=hfiar}}<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;{{HackagePackage|id=hinvaders}}<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;{{HackagePackage|id=mage}}<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;{{HackagePackage|id=MazesOfMonad}}<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on Hackage as {{HackagePackage|id=Monadius}}; see also the [http://www.youtube.com/watch?v=zqFgQiPKtOI video])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github], [https://github.com/keera-studios/monao New maintained version on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://sourceforge.net/projects/puzhs/ puzhs]<br />
:Haskell bindings to [https://code.google.com/p/puz/ libpuz]<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://srineet.brinkster.net/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;{{HackagePackage|id=Shu-thing}}<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;{{HackagePackage|id=SpaceInvaders}}<br />
:A video game, based on [[Yampa]]<br />
<br />
;{{HackagePackage|id=stunts}}<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Commercial games ===<br />
;[https://play.google.com/store/apps/details?id=uk.co.keera.games.magiccookies Magic Cookies!]<br />
:A lights-out clone for Android written in Haskell using SDL2 graphics and the FRP implementation Yampa. Created by [http://facebook.com/keerastudios Keera Studios].<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://allureofthestars.com Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the {{HackagePackage|id=LambdaHack}} roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [https://github.com/EricThoma/hchess hchess]<br />
: Incomplete toy chess engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[https://github.com/egonSchiele/actionkid actionkid]<br />
:A video game framework, with a [http://vimeo.com/109663514 video tutorial] and [https://github.com/egonSchiele/chips chips], a game based on it.<br />
<br />
;[[Bogre-Banana]]<br />
:A 3D game-engine for Haskell. It uses Haskell bindings to the OGRE 3D engine and OIS input system and a library called reactive-banana, to create a "Functional Reactive Programming" game-engine.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [https://github.com/haskell-game/fungen/blob/master/examples/hello.hs simple] [https://github.com/haskell-game/fungen/blob/master/examples/pong/pong.hs 2D] [https://github.com/haskell-game/fungen/blob/master/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
:[https://www.youtube.com/watch?v=v_GSbObYRkY Y-Wing flight] is a video of a demonstration of the possibilities of HGamer3D.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[https://github.com/asivitz/Hickory Hickory]<br />
:Hickory is not really a game engine. It's more of a collection of tools and abstractions that can be used to make games. It doesn't have opinions and doesn't force you into a particular paradigm.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
;[http://hackage.haskell.org/package/set-cover set-cover]<br />
:Solver for exact set cover problems. Included examples: [[Sudoku]], [[Mastermind]], [[Nonogram]], Domino tessellation, 8 Queens, Soma Cube, [[Tetris Cube]], Cube of L's, Logika's Baumeister puzzle. Generic algorithm allows to choose between slow but flexible Set from containers package and fast but cumbersome bitvectors.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://bananu7.github.io/Hate Hate]<br />
:Hate is a small framework for graphical haskell games and applications. It's heavily inspired by Love and aims at similar ease of use, but within the power of Haskell's type and concurrency safety.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/LambdaHack/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=60482Applications and libraries/Games2016-01-04T11:49:32Z<p>Lemming: use HackagePackage template</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;{{HackagePackage|id=babylon}}<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://www.haskell.org/communities/11-2015/html/report.html#sect7.13.5 Barbarossa]<br />
:A UCI chess engine written completely in Haskell<br />
<br />
;{{HackagePackage|id=boomslang}}<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend Defend The King from Forces of Different]<br />
: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]<br />
: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[http://mfuglos.github.io/jeopardy Fuglos Jeopardy]<br />
:Fuglos Jeopardy is a free implementation of a game resembling the popular quiz show 'Jeopardy'. It is written using Gtk2Hs as GUI toolkit. It is quite feature complete and easy to use. It contains support for LaTeX, so you can for example use LaTeX math syntax in your data sheets and thus organize a math jeopoardy event. Licensed under GPL3.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
; [https://github.com/ocharles/hadoom hadoom]<br />
:A clone of Doom, using reactive-banana, GTK, and the "diagrams" library.<br />
<br />
; [https://github.com/ivanperez-keera/haskanoid haskanoid]<br />
:An breakout game with SDL graphics and Kinect and Wiimote support. Written in FRP, there's a fork in Haskell for Android.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII Tetris in Haskell<br />
<br />
;{{HackagePackage|id=hfiar}}<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;{{HackagePackage|id=hinvaders}}<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;{{HackagePackage|id=mage}}<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;{{HackagePackage|id=MazesOfMonad}}<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on Hackage as {{HackagePackage|id=Monadius}}; see also the [http://www.youtube.com/watch?v=zqFgQiPKtOI video])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github], [https://github.com/keera-studios/monao New maintained version on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://sourceforge.net/projects/puzhs/ puzhs]<br />
:Haskell bindings to [https://code.google.com/p/puz/ libpuz]<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://srineet.brinkster.net/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;{{HackagePackage|id=Shu-thing}}<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;{{HackagePackage|id=SpaceInvaders}}<br />
:A video game, based on [[Yampa]]<br />
<br />
;{{HackagePackage|id=stunts}}<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Commercial games ===<br />
;[https://play.google.com/store/apps/details?id=uk.co.keera.games.magiccookies Magic Cookies!]<br />
:A lights-out clone for Android written in Haskell using SDL2 graphics and the FRP implementation Yampa. Created by [http://facebook.com/keerastudios Keera Studios].<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://allureofthestars.com Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the {{HackagePackage|id=LambdaHack}} roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [https://github.com/EricThoma/hchess hchess]<br />
: Incomplete toy chess engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[https://github.com/egonSchiele/actionkid actionkid]<br />
:A video game framework, with a [http://vimeo.com/109663514 video tutorial] and [https://github.com/egonSchiele/chips chips], a game based on it.<br />
<br />
;[[Bogre-Banana]]<br />
:A 3D game-engine for Haskell. It uses Haskell bindings to the OGRE 3D engine and OIS input system and a library called reactive-banana, to create a "Functional Reactive Programming" game-engine.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [https://github.com/haskell-game/fungen/blob/master/examples/hello.hs simple] [https://github.com/haskell-game/fungen/blob/master/examples/pong/pong.hs 2D] [https://github.com/haskell-game/fungen/blob/master/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
:[https://www.youtube.com/watch?v=v_GSbObYRkY Y-Wing flight] is a video of a demonstration of the possibilities of HGamer3D.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[https://github.com/asivitz/Hickory Hickory]<br />
:Hickory is not really a game engine. It's more of a collection of tools and abstractions that can be used to make games. It doesn't have opinions and doesn't force you into a particular paradigm.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
;[http://hackage.haskell.org/package/set-cover set-cover]<br />
:Solver for exact set cover problems. Included examples: [[Sudoku]], [[Mastermind]], [[Nonogram]], Domino tessellation, 8 Queens, Soma Cube, [[Tetris Cube]], Cube of L's, Logika's Baumeister puzzle. Generic algorithm allows to choose between slow but flexible Set from containers package and fast but cumbersome bitvectors.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://bananu7.github.io/Hate Hate]<br />
:Hate is a small framework for graphical haskell games and applications. It's heavily inspired by Love and aims at similar ease of use, but within the power of Haskell's type and concurrency safety.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/LambdaHack/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=60481Applications and libraries/Games2016-01-04T11:45:19Z<p>Lemming: set-cover: more examples, e.g. Mastermind and Nonogram</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://www.haskell.org/communities/11-2015/html/report.html#sect7.13.5 Barbarossa]<br />
:A UCI chess engine written completely in Haskell<br />
<br />
;[http://hackage.haskell.org/package/boomslang boomslang]<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend Defend The King from Forces of Different]<br />
: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]<br />
: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[http://mfuglos.github.io/jeopardy Fuglos Jeopardy]<br />
:Fuglos Jeopardy is a free implementation of a game resembling the popular quiz show 'Jeopardy'. It is written using Gtk2Hs as GUI toolkit. It is quite feature complete and easy to use. It contains support for LaTeX, so you can for example use LaTeX math syntax in your data sheets and thus organize a math jeopoardy event. Licensed under GPL3.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
; [https://github.com/ocharles/hadoom hadoom]<br />
:A clone of Doom, using reactive-banana, GTK, and the "diagrams" library.<br />
<br />
; [https://github.com/ivanperez-keera/haskanoid haskanoid]<br />
:An breakout game with SDL graphics and Kinect and Wiimote support. Written in FRP, there's a fork in Haskell for Android.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII Tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius Hackage]; see also the [http://www.youtube.com/watch?v=zqFgQiPKtOI video])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github], [https://github.com/keera-studios/monao New maintained version on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://sourceforge.net/projects/puzhs/ puzhs]<br />
:Haskell bindings to [https://code.google.com/p/puz/ libpuz]<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://srineet.brinkster.net/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://hackage.haskell.org/package/SpaceInvaders Space Invaders]<br />
:A video game, based on [[Yampa]]<br />
<br />
;[http://hackage.haskell.org/package/stunts stunts]<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Commercial games ===<br />
;[https://play.google.com/store/apps/details?id=uk.co.keera.games.magiccookies Magic Cookies!]<br />
:A lights-out clone for Android written in Haskell using SDL2 graphics and the FRP implementation Yampa. Created by [http://facebook.com/keerastudios Keera Studios].<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://allureofthestars.com Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the [http://hackage.haskell.org/package/LambdaHack LambdaHack] roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [https://github.com/EricThoma/hchess hchess]<br />
: Incomplete toy chess engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[https://github.com/egonSchiele/actionkid actionkid]<br />
:A video game framework, with a [http://vimeo.com/109663514 video tutorial] and [https://github.com/egonSchiele/chips chips], a game based on it.<br />
<br />
;[[Bogre-Banana]]<br />
:A 3D game-engine for Haskell. It uses Haskell bindings to the OGRE 3D engine and OIS input system and a library called reactive-banana, to create a "Functional Reactive Programming" game-engine.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [https://github.com/haskell-game/fungen/blob/master/examples/hello.hs simple] [https://github.com/haskell-game/fungen/blob/master/examples/pong/pong.hs 2D] [https://github.com/haskell-game/fungen/blob/master/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
:[https://www.youtube.com/watch?v=v_GSbObYRkY Y-Wing flight] is a video of a demonstration of the possibilities of HGamer3D.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[https://github.com/asivitz/Hickory Hickory]<br />
:Hickory is not really a game engine. It's more of a collection of tools and abstractions that can be used to make games. It doesn't have opinions and doesn't force you into a particular paradigm.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
;[http://hackage.haskell.org/package/set-cover set-cover]<br />
:Solver for exact set cover problems. Included examples: [[Sudoku]], [[Mastermind]], [[Nonogram]], Domino tessellation, 8 Queens, Soma Cube, [[Tetris Cube]], Cube of L's, Logika's Baumeister puzzle. Generic algorithm allows to choose between slow but flexible Set from containers package and fast but cumbersome bitvectors.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://bananu7.github.io/Hate Hate]<br />
:Hate is a small framework for graphical haskell games and applications. It's heavily inspired by Love and aims at similar ease of use, but within the power of Haskell's type and concurrency safety.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/LambdaHack/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Applications_and_libraries/Games&diff=60480Applications and libraries/Games2016-01-04T11:42:11Z<p>Lemming: set-cover package moved to mature packages</p>
<hr />
<div>{{LibrariesPage}}<br />
<br />
See also: [[Game Development]]<br />
<br />
<br />
== Games ==<br />
<br />
See also the [http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game Game] category on Hackage.<br />
<br />
;[http://hackage.haskell.org/package/babylon babylon]<br />
: An implementation of a simple 2-player board game. Uses wxHaskell.<br />
<br />
;[https://www.haskell.org/communities/11-2015/html/report.html#sect7.13.5 Barbarossa]<br />
:A UCI chess engine written completely in Haskell<br />
<br />
;[http://hackage.haskell.org/package/boomslang boomslang]<br />
: A clone of the popular Flash game Boomshine.<br />
<br />
;[https://github.com/yairchu/defend Defend The King from Forces of Different]<br />
: A simple multiplayer real time strategy game.<br />
<br />
; [http://www.increpare.com/2008/11/endless-cavern/ Endless Cavern]<br />
: A 2D procedurally-generated cave exploration game.<br />
<br />
;[http://sourceforge.net/projects/fooengine/?abmode=1 Foo]<br />
:Foo (abbreviation from football) is a playing machine of [http://en.wikipedia.org/wiki/Paper_Soccer Paper Soccer], a pencil and paper game for two players. It contains a simple interface using HOpenGL library and provides many playing algorithms.<br />
<br />
;[[Frag]]<br />
:Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong. It uses Yampa, Quake 3 BSP level format and OpenGL. It is licensed under the GPL.<br />
<br />
;[http://mfuglos.github.io/jeopardy Fuglos Jeopardy]<br />
:Fuglos Jeopardy is a free implementation of a game resembling the popular quiz show 'Jeopardy'. It is written using Gtk2Hs as GUI toolkit. It is quite feature complete and easy to use. It contains support for LaTeX, so you can for example use LaTeX math syntax in your data sheets and thus organize a math jeopoardy event. Licensed under GPL3.<br />
<br />
;[[GeBoP]]<br />
:The General Boardgames Player, offers a set of board games: Ataxx, Bamp, Halma, Hex, Kram, Nim, Reversi, TicTacToe, and Zenix. It uses wxHaskell.<br />
<br />
; [http://folk.uio.no/carljsv/gorillabas/GorillaBAS-0.1.tar.gz GorillaBAS]<br />
: A concrete game from an attempt on defining computer games.<br />
<br />
; [https://github.com/ocharles/hadoom hadoom]<br />
:A clone of Doom, using reactive-banana, GTK, and the "diagrams" library.<br />
<br />
; [https://github.com/ivanperez-keera/haskanoid haskanoid]<br />
:An breakout game with SDL graphics and Kinect and Wiimote support. Written in FRP, there's a fork in Haskell for Android.<br />
<br />
;[http://www.informatik.uni-bremen.de/~cxl/lehre/pi3.ws01/asteroids/ Haskell in Space]<br />
:An asteroid like game<br />
<br />
;[http://www.hedgewars.org/ Hedgewars]<br />
:A turn-based artillery game. The game server is written in Haskell.<br />
<br />
;[http://www.cs.ox.ac.uk/people/ian.lynagh/Hetris/ Hetris]<br />
:ASCII Tetris in Haskell<br />
<br />
;[http://hackage.haskell.org/package/hfiar hfiar]<br />
:Four in a Row in Haskell. Uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/hinvaders hinvaders]<br />
:A simple ANSI-graphics space invaders written entirely in Haskell 98.<br />
<br />
;[http://mu.org/~mux/LambdaChess/ LambdaChess]<br />
:GTK chess client<br />
<br />
;[http://quasimal.com/projects/level_0.html Level 0]<br />
:A fun and featureful Snake II clone using SDL.<br />
<br />
;[http://www.ncc.up.pt/~pbv/stuff/lostcities/ Lost Cities]<br />
:A two-player card game where each player tries to mount profitable expeditions. It uses wxHaskell.<br />
<br />
;[http://hackage.haskell.org/package/mage Mage]<br />
:Nethack clone written in Haskell (The web site have [http://www.scannedinavian.com/~shae/mage-1.0pre35.tar.gz this mage-1.0.pre35.tar.gz file] containing an older version that was using Data.FiniteMap.) There seems to be a problem with newer curses library even with the more recent 1.1.0 version.<br />
<br />
;[http://hackage.haskell.org/package/MazesOfMonad MazesOfMonad]<br />
:Role-Playing Game (influenced by Nethack), complete and fully playable. Console mode only.<br />
<br />
;[http://www.geocities.jp/takascience/haskell/monadius_en.html Monadius]<br />
:Monadius is a shoot 'em up with the selection bar power-up system for Windows, written in Haskell (now on [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Monadius Hackage]; see also the [http://www.youtube.com/watch?v=zqFgQiPKtOI video])<br />
<br />
;[http://mokehehe.blogspot.com/2009/04/super-nario-move-to-github.html Monao]<br />
:A Super Mario clone, using an SDL binding different from the one in Hackage: [https://github.com/mokehehe/monao Monao on github], [https://github.com/keera-studios/monao New maintained version on github]<br />
<br />
;[http://joyridelabs.de/game/ Nikki and the Robots]<br />
:A puzzle, platformer game.<br />
<br />
;[http://berlinbrowndev.blogspot.com/2007/09/octane-mech-opengl-haskell-based-mech.html Octane Mech]<br />
:Octane Mech, OpenGL Haskell based mech game<br />
<br />
;[http://sourceforge.net/projects/puzhs/ puzhs]<br />
:Haskell bindings to [https://code.google.com/p/puz/ libpuz]<br />
<br />
;[http://haskell-tetris.pbworks.com/w/page/16967421/Main OpenGL Tetris]<br />
:Tetris in Haskell with OpenGL<br />
<br />
;[http://srineet.brinkster.net/para/para.html Paratrooper]<br />
:Paratrooper is a simple action game that runs on Windows and is written in literate Haskell.<br />
<br />
;[http://raincat.bysusanlin.com/ Raincat]<br />
:2D puzzle game featuring a fuzzy little cat (uses GLUT)<br />
<br />
;[http://roguestar.downstairspeople.org Roguestar]<br />
:Roguestar is a science fiction adventure role playing game using Haskell and OpenGL.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Shu-thing Shu-thing]<br />
:A 2-D vector graphics upwards-scrolling keyboard-controlled shooter. You shoot the enemies while dodging their bullets until you reach and defeat the enemy.<br />
<br />
;[http://hackage.haskell.org/package/SpaceInvaders Space Invaders]<br />
:A video game, based on [[Yampa]]<br />
<br />
;[http://hackage.haskell.org/package/stunts stunts]<br />
:A revival of the classic racing game Stunts to serve as a non-toy-sized example for LambdaCube.<br />
<br />
;[https://github.com/nbartlomiej/tfoo Tfoo]<br />
:A simple Five in a Row game. Online, with server-sent events, deployed to [http://tfoo.herokuapp.com/ Heroku], open source.<br />
<br />
;[http://web.jfet.org/~kwantam/TriHs.tar.gz TriHs] (tar.gz)<br />
:A 1- or 2-player Tetris game using Gtk2Hs and Cairo.<br />
<br />
;[[wxAsteroids]]<br />
:Your space ship enters an asteroid belt, try to avoid collisions! wxAsteroids is based on wxHaskell.<br />
<br />
;[http://xiangqiboard.blogspot.com/2007/12/gnuxiangqi-angekndigt.html Xiangqiboard]<br />
:An implementation of xiangqi for Unix, using gtk2hs + cairo<br />
<br />
;{{HackagePackage | id =Yogurt}}<br />
:A functional MUD client featuring prioritized, regex-based hooks, variables, timers, logging, dynamic loading of Yogurt scripts and more. For example programs, please see [http://code.google.com/p/yogurt-mud/ Yogurt's home page]. <br />
<br />
=== Commercial games ===<br />
;[https://play.google.com/store/apps/details?id=uk.co.keera.games.magiccookies Magic Cookies!]<br />
:A lights-out clone for Android written in Haskell using SDL2 graphics and the FRP implementation Yampa. Created by [http://facebook.com/keerastudios Keera Studios].<br />
<br />
<br />
=== Unfinished/in-progress games ===<br />
<br />
;[http://allureofthestars.com Allure of the Stars]<br />
:A near-future Sci-Fi roguelike and tactical squad game. Long-term goals are high replayability and auto-balancing through procedural content generation and persistent content modification based on player behaviour. The game is written using the [http://hackage.haskell.org/package/LambdaHack LambdaHack] roguelike game engine.<br />
<br />
;[http://ipwnstudios.com/node/4 Bloodknight]<br />
:An action RPG for mobile devices<br />
<br />
; [https://github.com/ghulette/haskell-game-of-life haskell-game-of-life]<br />
: Conway's Game of Life<br />
<br />
; [https://github.com/EricThoma/hchess hchess]<br />
: Incomplete toy chess engine<br />
<br />
;[http://dotat.at/prog/life/hslife.hs HsLife]<br />
:A Haskell implementation of hashlife. It uses GLUT.<br />
<br />
== Game Engines and Libraries ==<br />
<br />
;[https://github.com/egonSchiele/actionkid actionkid]<br />
:A video game framework, with a [http://vimeo.com/109663514 video tutorial] and [https://github.com/egonSchiele/chips chips], a game based on it.<br />
<br />
;[[Bogre-Banana]]<br />
:A 3D game-engine for Haskell. It uses Haskell bindings to the OGRE 3D engine and OIS input system and a library called reactive-banana, to create a "Functional Reactive Programming" game-engine.<br />
<br />
;[http://hackage.haskell.org/package/bullet Bullet]<br />
:A wrapper for the Bullet physics engine.<br />
<br />
;[http://hackage.haskell.org/package/free-game free-game]<br />
:A GUI/game library based on free monads.<br />
<br />
;[http://hackage.haskell.org/package/FunGEn FunGEn]<br />
:FunGEn (Functional Game Engine) is a platform-independent BSD-licensed 2D game engine based on OpenGL and GLUT. Its light dependencies make it easy to install, however GLUT is reputed to be unsuitable for simultaneous keypresses. As of 2011 it's the only general-purpose game engine, and the quickest way to throw together [https://github.com/haskell-game/fungen/blob/master/examples/hello.hs simple] [https://github.com/haskell-game/fungen/blob/master/examples/pong/pong.hs 2D] [https://github.com/haskell-game/fungen/blob/master/examples/worms/worms.hs games], in Haskell. Example code: [http://joyful.com/fungen/site/example.html A Brief Example]. Forks and patches welcome!<br />
<br />
;[http://projects.haskell.org/game-tree/ game-tree]<br />
:game-tree is a purely functional library for searching game trees - useful for zero-sum two player games.<br />
<br />
;[http://hackage.haskell.org/package/GLFW-b GLFW-b]<br />
:Bindings to GLFW, a free, open source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time.<br />
<br />
;[http://gloss.ouroborus.net/ Gloss]<br />
:An OpenGL abstraction layer supporting game-style main loops.<br />
<br />
;[https://github.com/haskell-game haskell-game]<br />
:A project to make game development with Haskell easier to get started with by providing a suite of libraries for covering all sorts of aspects of game development.<br />
<br />
;[http://helm-engine.org/ Helm]<br />
:A functionally reactive game engine inspired by [http://elm-lang.org/ Elm].<br />
<br />
;[http://hackage.haskell.org/package/HGamer3D HGamer3D]<br />
:A game engine for Windows which includes Haskell bindings to a couple of C++ libraries and a Haskell API on top of that. Features include Audio, Joystick, Mouse and Keyboard handling, GUI, Network, Physics, 3D graphics. <br />
:[https://www.youtube.com/watch?v=v_GSbObYRkY Y-Wing flight] is a video of a demonstration of the possibilities of HGamer3D.<br />
<br />
;[http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Hipmunk Hipmunk]<br />
:Hipmunk: A Haskell binding for [http://chipmunk-physics.net/ Chipmunk]. Chipmunk is a fast, simple, portable, 2D physics engine. It is completely self-contained. See also [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HipmunkPlayground HipmunkPlayground]: a simple OpenGL program that allows you to see some of Hipmunk's functions in action.<br />
<br />
;[https://github.com/asivitz/Hickory Hickory]<br />
:Hickory is not really a game engine. It's more of a collection of tools and abstractions that can be used to make games. It doesn't have opinions and doesn't force you into a particular paradigm.<br />
<br />
;[[Hpysics]]<br />
:Hpysics is a physics engine written using Data Parallel Haskell during Google Summer of Code 2008.<br />
<br />
;[http://hackage.haskell.org/package/hogre hogre]<br />
:Haskell bindings to the excellent OGRE 3D rendering engine. Ogre has been used in commercial games such as Torchlight and several books exist documenting the Ogre API. Ogre uses an MIT license making it compatible with many Haskell libraries.<br />
<br />
;[http://hackage.haskell.org/package/IrrHaskell IrrHaskell]<br />
:Haskell binding to the [http://irrlicht.sourceforge.net/ Irrlicht game engine]. The Irrlicht Engine is an open source high performance realtime 3D engine<br />
<br />
;[http://lambdacube3d.wordpress.com/ LambdaCube 3D]<br />
:LambdaCube 3D is a domain specific language and library that makes it possible to program GPUs in a purely functional style.<br />
<br />
;[http://hackage.haskell.org/package/set-cover set-cover]<br />
:Solver for exact set cover problems. Included examples: Sudoku, 8 Queens, Soma Cube, Tetris Cube, Cube of L's, Logika's Baumeister puzzle. Generic algorithm allows to choose between slow but flexible Set from containers package and fast but cumbersome bitvectors.<br />
<br />
<br />
=== Unfinished/in-progress game engines/libraries ===<br />
<br />
;[https://github.com/adorablepuppy/CurryDog CurryDog]<br />
:Aims to be a 2d and 3d modular game engine.<br />
<br />
;[https://github.com/keera-studios/gtk-helpers gtk-helpers]<br />
:A collection of auxiliary operations related to Gtk2hs. See also [http://keera.co.uk/blog/2013/03/19/creating-board-games-in-haskell/ Creating board games in Haskell in 100 lines of code]<br />
<br />
;[[HaskGame]]<br />
:An incomplete graphics system abstraction layer.<br />
<br />
; [https://bananu7.github.io/Hate Hate]<br />
:Hate is a small framework for graphical haskell games and applications. It's heavily inspired by Love and aims at similar ease of use, but within the power of Haskell's type and concurrency safety.<br />
<br />
; [https://github.com/shicks/hsgame hsgame]<br />
:A framework for network games<br />
<br />
;[https://github.com/LambdaHack/LambdaHack LambdaHack]<br />
:A game engine library for roguelike games of arbitrary theme, size and complexity, packaged together with a small example dungeon crawler. When completed, it will let you specify content to be procedurally generated, define the AI behaviour on top of the generic content-independent rules and compile a ready-to-play game binary, using either the supplied or a custom-made main loop. Several frontends are available (GTK is the default) and many other generic engine components are easily overridden, but the fundamental source of flexibility lies in the strict and type-safe separation of code and content.<br />
<br />
<br />
[[Category:Games|*]]<br />
[[Category:Applications]]<br />
[[Category:Libraries]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Mastermind&diff=60479Mastermind2016-01-04T11:37:30Z<p>Lemming: Category:Games</p>
<hr />
<div>Mastermind is a board game where player A create a code of a number of symbols (colors, digits, letters) and player B has to guess the code. Player A evaluates every guess of the code using black pegs, meaning "right symbol at right place", and white pegs, meaning "right symbol at wrong place". Player B has to reconstruct the code using only these evaluations.<br />
<br />
It is a nice task to let the computer guess a code.<br />
Here are some solutions in Haskell:<br />
<br />
* {{HackagePackage|id=board-games}}: Uses an explicit representation of the set of all codes that match a certain evaluation.<br />
* {{HackagePackage|id=set-cover}}: Uses an exact set cover formulation of the property that a code matches an evaluation.<br />
* https://github.com/danielX/mastermind-haskell: Brute-force check of whether a code matches evaluations.<br />
* {{HackagePackage|id=mastermind}}<br />
<br />
<br />
There are also implementations focussing on the game player rather than a computer player:<br />
<br />
* http://hub.darcs.net/stepcut/mastermind<br />
* https://github.com/frerich/mastermind<br />
<br />
== See also ==<br />
<br />
* Wikipedia on [https://en.wikipedia.org/wiki/Mastermind_(game) Mastermind]<br />
<br />
[[Category:Games]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Mastermind&diff=60478Mastermind2016-01-04T11:31:57Z<p>Lemming: overview of Haskell implementations</p>
<hr />
<div>Mastermind is a board game where player A create a code of a number of symbols (colors, digits, letters) and player B has to guess the code. Player A evaluates every guess of the code using black pegs, meaning "right symbol at right place", and white pegs, meaning "right symbol at wrong place". Player B has to reconstruct the code using only these evaluations.<br />
<br />
It is a nice task to let the computer guess a code.<br />
Here are some solutions in Haskell:<br />
<br />
* {{HackagePackage|id=board-games}}: Uses an explicit representation of the set of all codes that match a certain evaluation.<br />
* {{HackagePackage|id=set-cover}}: Uses an exact set cover formulation of the property that a code matches an evaluation.<br />
* https://github.com/danielX/mastermind-haskell: Brute-force check of whether a code matches evaluations.<br />
* {{HackagePackage|id=mastermind}}<br />
<br />
<br />
There are also implementations focussing on the game player rather than a computer player:<br />
<br />
* http://hub.darcs.net/stepcut/mastermind<br />
* https://github.com/frerich/mastermind<br />
<br />
== See also ==<br />
<br />
* Wikipedia on [https://en.wikipedia.org/wiki/Mastermind_(game) Mastermind]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=60362Template:Main/Events2015-11-19T13:42:12Z<p>Lemming: BOB 2016</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
;[http://nfa.imn.htwk-leipzig.de/HAL2015/ HaL-10]<br />
:December 4-5, 2015, Leipzig, Germany<br />
<br />
;[http://foswiki.cs.uu.nl/foswiki/NlFpDay2016/WebHome Dutch Functional Programming Day 2016]<br />
:January 8, 2016, Utrecht University, The Netherlands<br />
<br />
;[http://bobkonf.de/2016/ BOB 2016]<br />
: What happens, if you don't choose the standard solution but the best one?<br />
:February 19, 2016, Berlin, Germany<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[http://wiki.haskell.org/Hac_Phi Hac Phi]<br />
:November 6-8, 2015<br />
<br />
;[http://wwwhome.cs.utwente.nl/~jankuper/fp-dag/ Dutch Functional Programming day (NL-FP 2015)]<br />
:January 9, 2015, University of Twente, The Netherlands<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=60361Template:Main/Events2015-11-19T13:40:49Z<p>Lemming: HaL-10</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
;[http://nfa.imn.htwk-leipzig.de/HAL2015/ HaL-10]<br />
:December 4-5, 2015, Leipzig, Germany<br />
<br />
;[http://foswiki.cs.uu.nl/foswiki/NlFpDay2016/WebHome Dutch Functional Programming Day 2016]<br />
:January 8, 2016, Utrecht University, The Netherlands<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[http://wiki.haskell.org/Hac_Phi Hac Phi]<br />
:November 6-8, 2015<br />
<br />
;[http://bobkonf.de/2015/ BOB 2015]<br />
: What happens, if you don't choose the standard solution but the best one?<br />
:January 23, 2015, Berlin, Germany<br />
<br />
;[http://wwwhome.cs.utwente.nl/~jankuper/fp-dag/ Dutch Functional Programming day (NL-FP 2015)]<br />
:January 9, 2015, University of Twente, The Netherlands<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands</div>Lemminghttps://wiki.haskell.org/index.php?title=Intentionally_omitted_instance&diff=59433Intentionally omitted instance2015-02-22T14:08:37Z<p>Lemming: summary of GHC tickets 7775 and 9334</p>
<hr />
<div>Consider you write the following in GHCi:<br />
<haskell><br />
Prelude> 2+3::Char<br />
<br />
<interactive>:2:2:<br />
No instance for (Num Char)<br />
arising from a use of `+'<br />
Possible fix: add an instance declaration for (Num Char)<br />
In the expression: 2 + 3 :: Char<br />
In an equation for `it': it = 2 + 3 :: Char<br />
</haskell><br />
In many cases users now actually try to implement <hask>instance Num Char</hask>,<br />
but this is certainly not a good idea.<br />
Is there a way to tell the user<br />
that the instance was left unimplemented by intention?<br />
Actually, this is possible with current Haskell extensions<br />
by implementing an instance with a depending instance that a user cannot fulfill:<br />
<haskell><br />
{-# LANGUAGE FlexibleContexts #-}<br />
{-# LANGUAGE UndecidableInstances #-}<br />
module Data.Char (Char) where<br />
<br />
class Unimplementable a where<br />
<br />
instance Unimplementable Char => Num Char where<br />
(+) = undefined<br />
(*) = undefined<br />
abs = undefined<br />
signum = undefined<br />
fromInteger = undefined<br />
</haskell><br />
<br />
The important point is to not export the <hask>Unimplementable</hask> class.<br />
<br />
It is ugly that you have to enable <hask>UndecidableInstances</hask> for this trick<br />
and you still have to suppress warnings about unimplemented methods.<br />
Thus it might be better have language support for prohibition of certain instances like in {{GHCTicket|id=9334|title="Instance chains"}}.<br />
<br />
<br />
== See also ==<br />
<br />
* {{GHCTicket|id=9334|title="Instance chains"}}<br />
* {{GHCTicket|id=7775|title="Mark intentionally omitted type class instances"}}<br />
<br />
[[Category:Idioms]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:GHCTicket&diff=59432Template:GHCTicket2015-02-22T13:49:36Z<p>Lemming: link to GHC Trac ticket</p>
<hr />
<div>[https://ghc.haskell.org/trac/ghc/ticket/{{{id}}} GHC ticket {{{id}}}: {{{title}}}]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=59203Template:Main/Events2015-01-11T19:53:04Z<p>Lemming: move NL-FP 2015 to recent events, remove NL-FP 2014</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
<br />
;[http://bobkonf.de/2015/ BOB 2015]<br />
: What happens, if you don't choose the standard solution but the best one?<br />
:January 23, 2015, Berlin, Germany<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[http://wwwhome.cs.utwente.nl/~jankuper/fp-dag/ Dutch Functional Programming day (NL-FP 2015)]<br />
:January 9, 2015, University of Twente, The Netherlands<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands<br />
<br />
;[http://iba-cg.de/hal9.html HaL-9]<br />
:June 20, 2014, Halle, Germany<br />
<br />
;[[ZuriHac2014|ZuriHac 2014]]<br />
:June 6-8, 2014, Zurich, Switzerland<br />
<br />
;[[BudapestHackathon2014|Budapest Hackathon 2014]]<br />
:May 31 - June 1, 2014, Budapest, Hungary<br />
<br />
;[[Hac NYC]] <br />
:April 4-6, 2014, New York City, US<br />
<br />
;[http://skillsmatter.com/event/scala/functional-programming-exchange-1819 Functional Programming eXchange 2014] <br />
:March 14, 2014, London, UK<br />
<br />
; Well-Typed's introductory and advanced [http://www.well-typed.com/services_training Haskell courses]<br />
:February 10-11 (Introductory) and February 12-13 (Advanced), 2014, London, UK</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Headlines&diff=59202Template:Main/Headlines2015-01-11T19:47:09Z<p>Lemming: GHC-7.8.4 released</p>
<hr />
<div><div class="subtitle">Headlines</div><br />
<br />
* ''2014:''<br />
** [http://www.haskell.org/ghc/ GHC 7.8.4] is released<br />
** The '''[http://www.haskell.org/platform/ Haskell Platform 2014.2]''' has been [http://www.haskell.org/pipermail/haskell/2014-August/024284.html released]<br />
<br />
* ''2013:''<br />
** '''[http://hackage.haskell.org/ Hackage 2]''' is now live, powered by Haskell.<br />
** '''[https://www.fpcomplete.com/business/haskell-center/overview/ FP Haskell Center]''', the commercial in-browser IDE by FP Complete '''[https://www.fpcomplete.com/business/blog/fp-complete-launches-fp-haskell-center-the-worlds-1st-haskell-ide-and-deployment-platform/ has been released]'''.<br />
** '''[http://www.haskell.org/pipermail/haskell/2013-September/039154.html Cabal 1.18]''' has been released.<br />
** The '''[http://haskell.org/platform?2013.2 Haskell Platform 2013.2]''' is now available<br />
** '''[http://www.fpcomplete.com FP Complete]''' has compiled a short '''[https://docs.google.com/forms/d/1dZVuT_2-x2C515YeXnAzXwddIvftALwgSoz2NYjS4aE/viewform survey]''' to help build the Haskell user community.<br />
<br />
* ''2012:''<br />
** The '''[http://haskell.org/platform Haskell Platform 2012.4]''' is now available<br />
** [http://www.haskell.org/ghc/ GHC 7.6] is released<br />
** The '''[http://haskell.org/platform Haskell Platform 2012.2]''' is now available<br />
** [http://www.yesodweb.com/blog/2012/04/announcing-yesod-1-0 Yesod 1.0] is now available<br />
** [http://www.haskell.org/ghc/ GHC 7.4] is released<br />
** O'Reilly have announced a forthcoming book on [http://www.haskell.org/pipermail/haskell/2012-May/023328.html Parallel and Concurrent Haskell]</div>Lemminghttps://wiki.haskell.org/index.php?title=Liquid_Haskell&diff=59139Liquid Haskell2014-12-06T22:59:30Z<p>Lemming: link to Blog</p>
<hr />
<div>Liquid Haskell allows to annotate code with invariants<br />
that complement the invariants imposed by the types.<br />
These invariants are checked with an SMT solver.<br />
Such invariants may be non-negative numbers, sorted lists, matching lengths of lists, membership of certain elements in a <hask>Set</hask> or <hask>Map</hask>.<br />
<br />
* Hackage: {{HackagePackage|id=liquidhaskell}}<br />
* [http://goto.ucsd.edu/~rjhala/liquid/haskell/blog/ Blog]<br />
* [http://goto.ucsd.edu/liquidhaskell Online demo]<br />
<br />
== See also ==<br />
<br />
* [[Catch]]<br />
* [[ESC]]<br />
<br />
[[Category:Development tools]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=59070Template:Main/Events2014-10-31T10:54:42Z<p>Lemming: BOB 2015</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
<br />
;[http://bobkonf.de/2015/ BOB 2015]<br />
: What happens, if you don't choose the standard solution but the best one?<br />
:January 23, 2015, Berlin, Germany<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands<br />
<br />
;[http://iba-cg.de/hal9.html HaL-9]<br />
:June 20, 2014, Halle, Germany<br />
<br />
;[[ZuriHac2014|ZuriHac 2014]]<br />
:June 6-8, 2014, Zurich, Switzerland<br />
<br />
;[[BudapestHackathon2014|Budapest Hackathon 2014]]<br />
:May 31 - June 1, 2014, Budapest, Hungary<br />
<br />
;[[Hac NYC]] <br />
:April 4-6, 2014, New York City, US<br />
<br />
;[http://skillsmatter.com/event/scala/functional-programming-exchange-1819 Functional Programming eXchange 2014] <br />
:March 14, 2014, London, UK<br />
<br />
; Well-Typed's introductory and advanced [http://www.well-typed.com/services_training Haskell courses]<br />
:February 10-11 (Introductory) and February 12-13 (Advanced), 2014, London, UK<br />
<br />
;[http://staff.science.uva.nl/~grelck/nl-fp-day-2014.html NL-FP day 2014] <br />
:January 10, 2014, Amsterdam, NLD</div>Lemminghttps://wiki.haskell.org/index.php?title=Peano_numbers&diff=59040Peano numbers2014-10-24T12:07:14Z<p>Lemming: /* Peano number values */ update link to code.haskell.org</p>
<hr />
<div>'''Peano numbers''' are a simple way of representing the natural numbers using only a zero value and a successor function. In Haskell it is easy to create a type of Peano number values, but since unary representation is inefficient, they are more often used to do [[type arithmetic]] due to their simplicity.<br />
<br />
== Overview ==<br />
<br />
=== Peano number values ===<br />
<br />
<haskell><br />
data Peano = Zero | Succ Peano<br />
</haskell><br />
<br />
Here <hask>Zero</hask> and <hask>Succ</hask> are values (constructors). <hask>Zero</hask> has type <hask>Peano</hask>, and <hask>Succ</hask> has type <hask>Peano -> Peano</hask>. The natural number zero is represented by <hask>Zero</hask>, one by <hask>Succ Zero</hask>, two by <hask>Succ (Succ Zero)</hask> and so forth.<br />
<br />
Here's a simple addition function:<br />
<br />
<haskell><br />
add Zero b = b<br />
add (Succ a) b = Succ (add a b)<br />
</haskell><br />
<br />
See an [http://code.haskell.org/~thielema/htam/src/Number/PeanoNumber.hs example implementation].<br />
<br />
=== Peano number types ===<br />
<br />
<haskell><br />
data Zero<br />
data Succ a<br />
</haskell><br />
<br />
Here <hask>Zero</hask> and <hask>Succ</hask> are types. <hask>Zero</hask> has kind <hask>*</hask>, and <hask>Succ</hask> has kind <hask>* -> *</hask>. The natural numbers are represented by types (of kind <hask>*</hask>) <hask>Zero</hask>, <hask>Succ Zero</hask>, <hask>Succ (Succ Zero)</hask> etc.<br />
<br />
Arithmetic can be done using [[fundep]]s:<br />
<br />
<haskell><br />
class Add a b ab | a b -> ab<br />
instance Add Zero b b<br />
instance (Add a b ab) => Add (Succ a) b (Succ ab)<br />
</haskell><br />
<br />
Note that classes express relationships between types, rather than functions from type to type. Accordingly, with the instance declarations above one can add another fundep to the class declaration to get subtraction for free:<br />
<br />
<haskell><br />
class Add a b ab | a b -> ab, a ab -> b<br />
instance Add Zero b b<br />
instance (Add a b ab) => Add (Succ a) b (Succ ab)<br />
</haskell><br />
<br />
See [[type arithmetic]] for other functions and encodings.<br />
<br />
== Applications ==<br />
<br />
=== Lazy counting ===<br />
<br />
The lazy nature of Peano numbers rehabilitates the use of list functions which count list elements.<br />
As described in [[Things to avoid#Don.27t_ask_for_the_length_of_a_list_when_you_don.27t_need_it|Things to avoid]]<br />
one should not write<br />
<haskell><br />
length xs == 0<br />
</haskell><br />
because <hask>length</hask> traverses the whole list and may take a long time doing so, although after you have seen only one, it is obvious that the list is not empty.<br />
The above expression can be simply replaced by <hask>null</hask>, but with Peano numbers you achieve the same<br />
<haskell><br />
genericLength xs == Zero<br />
-- or<br />
genericLength xs == (0::Peano)<br />
</haskell><br />
<br />
The expression<br />
<haskell><br />
length xs == length ys<br />
</haskell><br />
is harder to make lazy without Peano numbers.<br />
With them (and an appropriate <hask>Num</hask> instance) this becomes rather simple, because<br />
<haskell><br />
genericLength xs == (genericLength ys :: Peano)<br />
</haskell><br />
traverses only as many list nodes as are in the shorter list.<br />
<br />
=== Equation solving ===<br />
<br />
Lazy Peano numbers can also be used within "[[Tying the Knot]]" techniques.<br />
There is a [http://darcs.haskell.org/unique-logic/haskell98/src/UniqueLogic/Lazy/Peano.hs package] for determining the right order for solving equations,<br />
where an equation is only solved if only one of its variables is still indeterminate.<br />
<br />
<br />
== See also ==<br />
<br />
See example implementations:<br />
* [http://darcs.haskell.org/htam/src/Number/PeanoNumber.hs using standard Prelude]<br />
* using [[Numeric Prelude]] [http://darcs.haskell.org/numericprelude/src/Number/Peano.hs type classes]<br />
<br />
[[Category:Mathematics]]<br />
[[Category:Idioms]]<br />
[[Category:Glossary]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Headlines&diff=58891Template:Main/Headlines2014-09-24T17:17:36Z<p>Lemming: GHC 7.8.2 -> 7.8.3</p>
<hr />
<div><div class="subtitle">Headlines</div><br />
<br />
* ''2014:''<br />
** The '''[http://www.haskell.org/platform/ Haskell Platform 2014.2]''' has been [http://www.haskell.org/pipermail/haskell/2014-August/024284.html released]<br />
** [http://www.haskell.org/ghc/ GHC 7.8.3] is released<br />
<br />
* ''2013:''<br />
** '''[http://hackage.haskell.org/ Hackage 2]''' is now live, powered by Haskell.<br />
** '''[https://www.fpcomplete.com/business/haskell-center/overview/ FP Haskell Center]''', the commercial in-browser IDE by FP Complete '''[https://www.fpcomplete.com/business/blog/fp-complete-launches-fp-haskell-center-the-worlds-1st-haskell-ide-and-deployment-platform/ has been released]'''.<br />
** '''[http://www.haskell.org/pipermail/haskell/2013-September/039154.html Cabal 1.18]''' has been released.<br />
** The '''[http://haskell.org/platform?2013.2 Haskell Platform 2013.2]''' is now available<br />
** '''[http://www.fpcomplete.com FP Complete]''' has compiled a short '''[https://docs.google.com/forms/d/1dZVuT_2-x2C515YeXnAzXwddIvftALwgSoz2NYjS4aE/viewform survey]''' to help build the Haskell user community.<br />
<br />
* ''2012:''<br />
** The '''[http://haskell.org/platform Haskell Platform 2012.4]''' is now available<br />
** [http://www.haskell.org/ghc/ GHC 7.6] is released<br />
** The '''[http://haskell.org/platform Haskell Platform 2012.2]''' is now available<br />
** [http://www.yesodweb.com/blog/2012/04/announcing-yesod-1-0 Yesod 1.0] is now available<br />
** [http://www.haskell.org/ghc/ GHC 7.4] is released<br />
** O'Reilly have announced a forthcoming book on [http://www.haskell.org/pipermail/haskell/2012-May/023328.html Parallel and Concurrent Haskell]</div>Lemminghttps://wiki.haskell.org/index.php?title=Causal_Commutative_Arrows&diff=58810Causal Commutative Arrows2014-09-12T10:47:07Z<p>Lemming: Categories</p>
<hr />
<div>{{HackagePackage|id=CCA}}<br />
<br />
* [http://haskell.cs.yale.edu/?post_type=publication&p=573 Causal Commutative Arrows]<br />
* [http://haskell.cs.yale.edu/?post_type=publication&p=72 Causal Commutative Arrows and Their Optimization]<br />
** [http://vimeo.com/6652662 video]<br />
<br />
* [http://arxiv.org/abs/1004.4796 Compiling Signal Processing Code embedded in Haskell via LLVM]: Describes the use of causal arrows for generating LLVM code for signal processing. A fusion framework is not required, since every arrow is implemented in a canonical form.<br />
<br />
[[Category:Arrow]]<br />
[[Category:Music]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Causal_Commutative_Arrows&diff=58809Causal Commutative Arrows2014-09-12T10:45:22Z<p>Lemming: LLVM-arrows</p>
<hr />
<div>{{HackagePackage|id=CCA}}<br />
<br />
* [http://haskell.cs.yale.edu/?post_type=publication&p=573 Causal Commutative Arrows]<br />
* [http://haskell.cs.yale.edu/?post_type=publication&p=72 Causal Commutative Arrows and Their Optimization]<br />
** [http://vimeo.com/6652662 video]<br />
<br />
* [http://arxiv.org/abs/1004.4796 Compiling Signal Processing Code embedded in Haskell via LLVM]: Describes the use of causal arrows for generating LLVM code for signal processing. A fusion framework is not required, since every arrow is implemented in a canonical form.</div>Lemminghttps://wiki.haskell.org/index.php?title=What_a_Monad_is_not&diff=58615What a Monad is not2014-07-26T17:17:22Z<p>Lemming: /* Warning */ update "warm fuzzy" link, originally referenced article seemed to be named "understanding monad", too</p>
<hr />
<div>==Warning==<br />
Don't be surprised if you leave this page more confused than before. That just means that it has successfully destroyed your false assumptions, or that you've fallen for some horrible inside joke. Beware of [[Zygohistomorphic prepromorphisms]]. Go for [http://en.wikibooks.org/wiki/Haskell/Understanding_monads warm and fuzzy], instead.<br />
<br />
==Monads are not a good choice as topic for your first Haskell blog entry==<br />
...just accept that they're [http://blog.plover.com/prog/burritos.html burritos], and wait until later.<br />
<br />
==Monads are not a language feature==<br />
Really. They are defined in terms of Haskell, not Haskell in terms of them. Conversely,<br />
<br />
==Haskell doesn't need Monads==<br />
...well, apart from the current Haskell standard defining the way IO is done in terms of Monads: [http://donsbot.wordpress.com/2009/01/31/reviving-the-gofer-standard-prelude-circa-1994/ It could be done differently and still work].<br />
<br />
==Monads are not impure==<br />
...In no way whatsoever. You don't even need flexible morals to claim it. To be more specific, it's IO that's impure. That makes the IO monad impure. But that's not a general property of monads - just IO. And even then, we can pretend that Haskell is a purely functional description language for imperative programs. But we didn't want to employ flexible morals, now did we?<br />
<br />
==Monads are not about state==<br />
While it is certainly possible to abstract away explicit state passing by using a Monad, that's not what a monad is. Some examples for monads that are not about state: Identity monad, Reader monad, List monad, Continuation monad, Exception monad.<br />
<br />
==Monads are not about strictness==<br />
Monad operations (bind and return) have to be [[Non-strict semantics|non-strict]] in fact, always! However<br />
other operations can be specific to each monad.<br />
For instance some are strict (like IO), and some are non-strict (like []). Then there are some that come in multiple flavours, like State.<br />
<br />
Try the following:<br />
<br />
<haskell><br />
runState (sequence . repeat $ state (\x -> (x,x+1))) 0<br />
</haskell><br />
<br />
Having a look at the implementation of fixIO might be helpful, too.<br />
<br />
==Monads are not values==<br />
This point might be driven home best by pointing out that instance Monad Foo where ... is not a data type, but a declaration of a typeclass instance. However, to elaborate:<br />
<br />
Monads are not values in the same sense that addition and multiplication are not numbers: They capture a -- very specific -- relationship between values of a specific domain into a common abstraction. We're going to call these values monads manage ''mobits'', somewhat like this:<br />
<br />
<haskell><br />
type Mobit m a = Monad m => m a<br />
</haskell><br />
<br />
The IO monad manages mobits representing side-effects ("IO actions").<br />
<br />
The List monad manages mobits representing multiple values ("[a]")<br />
<br />
The Reader monads manages mobits that are pure computations that use asks to propagate information instead of explicit arguments<br />
<br />
...and while addition and multiplication are both monoids over the positive natural numbers, a monad is a monoid object in a category of endofunctors: return is the unit, and join is the binary operation. It couldn't be more simple. If that confuses you, it might be helpful to see a Monad as a lax functor from a terminal bicategory.<br />
<br />
==Monads are not a replacement for applicative functors==<br />
Instead, every monad ''is'' an applicative functor (as well as a functor). It is considered good practice not to use >>= if all you need is <*>, or even fmap.<br />
<br />
Not confusing which features of monads are specific to monads only and which stem from applicative functors is vitally important for a deeper understanding of monads. As an example, the applicative functor interface of parser libraries can parse context-free languages (modulo hacks abusing open recursion), while the monadic interface can parse context-sensitive grammars: Monads allow you to influence further processing by inspecting the result of your parse. To understand why, have a look at the type of >>=. To understand why applicative functors by themselves are sufficient to track the current parsing position and express sequencing, have a look at the [http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-044.pdf uu-parsinglib tutorial (pdf)].<br />
<br />
The exact differences are elaborated in even greater detail in Brent Yorgey's excellent [[Typeclassopedia]].<br />
<br />
==Monads are not about ordering/sequencing==<br />
Monads are commonly used to order sequences of computations. But this is misleading. Just as you can use monads for state, or strictness, you can use them to order computations. But there are also commutative monads, like Reader, that don't order anything. So ordering is not in any way essential to what a monad is.<br />
<br />
Let's have a look at what's meant by ordering. Consider an expression like<br />
<br />
<haskell><br />
let x = a<br />
y = b<br />
in f x y<br />
</haskell><br />
<br />
That gives the same result as<br />
<br />
<haskell><br />
let y = b<br />
x = a<br />
in f x y<br />
</haskell><br />
<br />
It doesn't matter what order we write the two bindings. But for doing I/O we'd like ordering. Monads allow us to express<br />
<br />
<haskell><br />
do<br />
x <- getChar<br />
y <- getChar<br />
return (x,y)<br />
</haskell><br />
<br />
and have it be different from<br />
<br />
<haskell><br />
do<br />
y <- getChar<br />
x <- getChar<br />
return (x,y)<br />
</haskell><br />
<br />
Unlike the first, the second example returns a pair of characters in the opposite order to which they were entered.<br />
<br />
It might help to meditate about the difference between 'assignment' and 'binding', right now.<br />
<br />
However, just to spoil the enlightenment you just attained, there are monads for which swapping the order of lines like this makes no difference: For example, the Reader monad.<br />
<br />
So while it is correct to say that monads can be used to order operations, it would be wrong to say that monads are a mechanism for ordering operations.<br />
<br />
This notion of commutativity looks superficially very different from the familiar one in vanilla algebra where a+b=b+a. It doesn't mean that<br />
<haskell><br />
m >> n === n >> m<br />
</haskell><br />
which doesn't hold in general for ''any'' non-trivial monad, as for the most part<br />
<haskell><br />
return 1 >> return 2 === return 2 =/= return 1 === return 2 >> return 1<br />
</haskell><br />
<br />
This shouldn't be too surprising, though, as >> isn't the binary operation of a monoid. The [http://ncatlab.org/nlab/show/commutative+algebraic+theory category-theoretic definition] of a commutative monad is rather more abstract.<br />
<br />
==See also==<br />
<br />
* [[Do notation considered harmful]]<br />
<br />
[[Category:FAQ]]<br />
[[Category:Monad]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Avoiding_partial_functions&diff=58614Avoiding partial functions2014-07-26T07:24:12Z<p>Lemming: /* init, last */ links to utility-ht:viewR and switchR</p>
<hr />
<div>There are several [[partial functions]] in the Haskell standard library.<br />
If you use them, you always risk to end up with an undefined.<br />
In this article we give some hints how to avoid them, leading to code that you can be more confident about.<br />
<br />
For a partial function f the general pattern is:<br />
Whereever we write "check whether x is in the domain of f before computing f x",<br />
we replace it by combination of check and computation of f.<br />
<br />
== fromJust ==<br />
<br />
You should replace<br />
<haskell><br />
if isNothing mx<br />
then g<br />
else h (fromJust mx)<br />
</haskell><br />
by<br />
<haskell><br />
case mx of<br />
Nothing -> g<br />
Just x -> h x<br />
</haskell><br />
which is equivalent to<br />
<haskell><br />
maybe g h mx<br />
</haskell><br />
<br />
== head, tail ==<br />
<br />
You should replace<br />
<haskell><br />
if null xs<br />
then g<br />
else h (head xs) (tail xs)<br />
</haskell><br />
by<br />
<haskell><br />
case xs of<br />
[] -> g<br />
y:ys -> h y ys<br />
</haskell><br />
<br />
== init, last ==<br />
<br />
You may replace<br />
<haskell><br />
if null xs<br />
then g<br />
else h (init xs) (last xs)<br />
</haskell><br />
by<br />
<haskell><br />
case xs of<br />
[] -> g<br />
y:ys -> uncurry h $ viewRTotal y ys<br />
<br />
viewRTotal :: a -> [a] -> ([a], a)<br />
viewRTotal x xs =<br />
forcePair $<br />
foldr<br />
(\x0 go y -> case go y of ~(zs,z) -> (x0:zs,z))<br />
(\y -> ([],y))<br />
xs x<br />
<br />
forcePair :: (a,b) -> (a,b)<br />
forcePair ~(a,b) = (a,b)<br />
</haskell><br />
<br />
Alternatively, you may import from {{HackagePackage|id=utility-ht}}:<br />
* [http://hackage.haskell.org/packages/archive/utility-ht/0.0.8/doc/html/Data-Tuple-HT.html forcePair]<br />
* [http://hackage.haskell.org/packages/archive/utility-ht/0.0.8/doc/html/Data-List-HT.html viewR]<br />
* [http://hackage.haskell.org/packages/archive/utility-ht/0.0.8/doc/html/Data-List-HT.html switchR].<br />
<br />
== (!!) ==<br />
<br />
You should replace<br />
<haskell><br />
if k < length xs<br />
then xs!!k<br />
else y<br />
</haskell><br />
by<br />
<haskell><br />
case drop k xs of<br />
x:_ -> x<br />
[] -> y<br />
</haskell><br />
<br />
This is also more lazy, since for computation of <hask>length</hask> you have to visit every element of the list.<br />
<br />
<br />
== irrefutable pattern match on (:) ==<br />
<br />
You should replace<br />
<haskell><br />
if k < length xs<br />
then let (prefix,x:suffix) = splitAt k xs<br />
in g prefix x suffix<br />
else y<br />
</haskell><br />
by<br />
<haskell><br />
case splitAt k xs of<br />
(prefix,x:suffix) -> g prefix x suffix<br />
(_,[]) -> y<br />
</haskell><br />
<br />
<br />
== minimum ==<br />
<br />
The function <hask>isLowerLimit</hask> checks if a number is a lower limit to a sequence.<br />
You may implement it with the partial function <hask>minimum</hask>.<br />
<haskell><br />
isLowerLimit :: Ord a => a -> [a] -> Bool<br />
isLowerLimit x ys = x <= minimum ys<br />
</haskell><br />
It fails if <hask>ys</hask> is empty or infinite.<br />
<br />
You should replace it by<br />
<haskell><br />
isLowerLimit x = all (x<=)<br />
</haskell><br />
This definition terminates for infinite lists, if <hask>x</hask> is not a lower limit. It aborts immediately if an element is found which is below <hask>x</hask>.<br />
Thus it is also faster for finite lists.<br />
Even more: It also works for empty lists.<br />
<br />
<br />
[[Category:Tutorials]]<br />
[[Category:Style]]<br />
[[Category:Idioms]]</div>Lemminghttps://wiki.haskell.org/index.php?title=CSound&diff=58567CSound2014-07-14T10:13:10Z<p>Lemming: update link to HasSound</p>
<hr />
<div>[http://www.csounds.com/ Csound] is a sound design, music synthesis, and signal processing system, providing facilities for composition and performance over a wide range of platforms. <br />
<br />
For Haskell there exist several interfaces to CSound:<br />
<br />
* {{HackagePackage|id=hCsound}} by John Lato provides direct access to CSounds runtime.<br />
* Translation from Haskell expressions to CSound Orchestra and Score expressions written by Matt Zamec and Sarah Eisenstat. This was part of [[Haskore]] and is now part of [http://www.cs.yale.edu/homes/hudak-paul/CS431F06/HasSoundManual.html HasSound].<br />
<br />
<br />
[[Category:Music]]<br />
[[Category:Packages]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Haskore&diff=58566Haskore2014-07-14T10:09:31Z<p>Lemming: See also: remove doubled newline</p>
<hr />
<div>[http://www.haskell.org/haskore/ Haskore] is a set of Haskell modules for creating, analysing and manipulating music.<br />
Music can be made audible through various back-ends. (See below.)<br />
A more recent, but less stable version, is available as [[Darcs]] repository at http://code.haskell.org/haskore/revised/.<br />
<br />
==Features==<br />
<br />
===Example===<br />
<br />
To get an impression how intuitive music composition with Haskore is, see the following example code (runs with revised Haskore):<br />
<haskell><br />
chords =<br />
(c 0 qn () =:= e 0 qn () =:= g 0 qn ()) +:+<br />
(c 0 qn () =:= f 0 qn () =:= a 0 qn ()) +:+<br />
(d 0 qn () =:= g 0 qn () =:= b 0 qn ())<br />
<br />
song =<br />
MidiMusic.fromMelodyNullAttr MidiMusic.AcousticGrandPiano<br />
(Music.transpose (-48) (Music.changeTempo 3 chords))<br />
</haskell><br />
<br />
The <hask>(=:=)</hask> means parallel composition and<br />
<hask>(+:+)</hask> means serial composition of musical objects.<br />
<br />
===Backends===<br />
<br />
Ideally you can compose a song once in Haskore, and then play it by several back-ends.<br />
Practically this is more difficult, since all back-ends have different functionality (otherwise there wouldn't be so many).<br />
<br />
These back-ends are currently supported:<br />
* [[MIDI]] (both file and realtime)<br />
* [[CSound]]<br />
* [[SuperCollider]]<br />
* [[Synthesizer|Audio files]] rendered by pure Haskell code.<br />
<br />
ToDo:<br />
* Notation output (Lilypond, partially done in CAEC, see below).<br />
<br />
==Community==<br />
<br />
There is no Haskore related mailing list, but Haskore related discussion is very welcome at the [[Haskell art]] mailing list.<br />
<br />
==Getting started==<br />
<br />
=== Platforms ===<br />
<br />
The core Haskore can run on both Linux and Windows.<br />
Only various back-ends and real-time functionality are critical.<br />
So far, real-time playback and use of [[SuperCollider]] is only usable on Linux.<br />
<br />
In future Haskore should consist of a small core for music composition, analysis and manipulation<br />
and separate packages for connecting to various back-ends and separated real-time stuff.<br />
The splitting made some progress, but is still not at its end.<br />
<br />
<!--<br />
==== UNIX/Linux ====<br />
<br />
The original Haskore was mainly developed on Windows,<br />
whereas the revised version was developed mainly in Linux.<br />
So least hassle is currently caused on Linux.<br />
<br />
==== Windows ====<br />
<br />
* http://www.haskell.org/pipermail/haskell-cafe/2008-June/043905.html<br />
* http://www.haskell.org/pipermail/haskell-cafe/2008-August/045911.html - Some hacks to get Haskore running on Windows quickly. The right thing to do would be to factor out the real-time stuff, since it is in general hard to port.<br />
--><br />
<br />
=== Installation using cabal ===<br />
<br />
(There are more detailed installation instructions [http://github.com/nfjinjing/haskore-guide/tree/master/doc/install.markdown here], if the following does not work)<br />
<br />
Prerequisites: You should be able to fetch a package using [[Darcs]] and configure/build/install it using [[Cabal/How_to_install_a_Cabal_package|cabal]].<br />
<br />
Step 0. Since it is the most convenient way of installation, try to install as many as possible packages from [[Hackage]] using cabal-install. Not all packages are available on Hackage because of their experimental state.<br />
<br />
cabal install midi # this will also install non-negative, event-list<br />
cabal install data-accessor<br />
cabal install markov-chain<br />
<br />
Step 1. Install the remaining packages such that at the end the following packages are installed:<br />
<br />
non-negative, event-list, data-accessor, markov-chain, midi, haskore<br />
<br />
If cabal-install worked, there should only <code>haskore</code> be left for installation.<br />
<br />
Step 2. Choose a folder where some haskell packages can be stored.<br />
<br />
Step 3. Get the packages. That is, for each PACKAGE call<br />
<br />
darcs get http://code.haskell.org/PACKAGE<br />
or<br />
darcs get http://code.haskell.org/~thielema/PACKAGE<br />
<br />
Step 4. Build and install the packages that you got by darcs. For each PACKAGE (in the order of above)<br />
<br />
cd PACKAGE<br />
runhaskell Setup.lhs configure (--prefix=/usr/local --user)<br />
runhaskell Setup.lhs build<br />
runhaskell Setup.lhs install<br />
<br />
Step 5. On Linux you may also wish to use SuperCollider.<br />
If you are uncertain, if it is worth the trouble, then listen to the examples given in the [[#Links|Links]] section.<br />
SuperCollider support requires installation of the packages <code>haskore-realtime</code> and <code>haskore-supercollider</code> in the way that is described above.<br />
<br />
Step 6. To get something to listen follow the hints in the [http://code.haskell.org/haskore/revised/Readme Readme] file of the <code>haskore</code> package.<br />
<br />
==Projects==<br />
<br />
A lot of projects were initiated that use the Haskore framework or something in the spirit of Haskore.<br />
This page may help to keep an overview of all projects.<br />
All maintainers of Haskore related projects are encouraged to add their project here and keep the references up to date.<br />
<br />
{|<br />
| [http://www.techfak.uni-bielefeld.de/ags/pi/lehre/AuDIWS02/musik/ AuDi] || Peter Steffen || Course material for Algorithms and Data Structures I - A formula language for music ("Algorithmen und Datenstrukturen I - Eine Formelsprache fuer Musik")<br />
|-<br />
| [http://www.mpi-sb.mpg.de/~ratschan/autotrack/ AutoTrack] || Stefan Ratschan || A tool for creating practizing and demo tracks from chord charts. You feed the program with a chord chart, set the desired style (jazz, bossa, etc.), tempo, key etc. and it produces a simple MIDI file containing an according bass and drum track. Includes a lot of examples.<br />
|-<br />
| [http://code.haskell.org/haskore/revised/related/etude/ CAEC] || Matt Munz || Computer-Aided Etude Composition in Haskell<br />
|-<br />
| [http://code.haskell.org/haskore/revised/ Design experiments] || Henning Thielemann || Test of several changes of Haskore's design targetting at more flexibility and consistency<br />
|-<br />
| [http://www.netsoc.tcd.ie/~bermo/4ba3/report.pdf Emile] || Adam Bermingham || Eight-Bar Melody Generation in Haskell. Automatic composition based on two initial bars<br />
|-<br />
| [http://www.imn.htwk-leipzig.de/~waldmann/ Gore] || Johannes Waldmann || Convert a melody description in a string into the Haskore Music data structure. Thus simple melodies can be written much more condensed.<br />
|-<br />
| [http://meltin.net/hacks/haskell/ HasChorus] || Martin Schwenke || A set of Haskell modules written on top of Haskore to make it easier to sequence simple, repetitive music<br />
|-<br />
| [http://www.idiap.ch/~paiement/ Jazkore] || Jean-François Paiement || A model of melodic jazz improvisation in functional programming<br />
|-<br />
| Lilypond back-end || Jeffrey R. Lewis || A back-end for Haskore to produce Lilypond notation files.<br />
|-<br />
| [http://www.haskell.org/pipermail/haskell-cafe/2006-September/018144.html Microtonal music] || Magnus Jonsson || This is not Haskore related, though integration into Haskore would be nice<br />
|-<br />
| [http://haskell.cs.yale.edu/yale/papers/polymedia/hudak-RR-1259.pdf Polymorphic Temporal Media] || Paul Hudak || An Algebraic Theory of Polymorphic Temporal Media - A generalization of Haskore Music and MDL as well as Fran and FAL animation<br />
|-<br />
| [http://www.cafepress.com/haskore.13482964 T-shirt] || Fritz Ruehr || Haskore T-Shirt featuring the 8 laws of polymorphic temporal media<br />
|}<br />
<br />
== Papers ==<br />
<br />
* Paul Hudak: [http://haskell.cs.yale.edu/yale/papers/polymedia/hudak-RR-1259.pdf An Algebraic Theory of Polymorphic Temporal Media - A generalization of Haskore Music and MDL as well as Fran and FAL animation]<br />
* Henning Thielemann: [http://dafx04.na.infn.it/WebProc/Proc/P_201.pdf Audio Processing using Haskell]<br />
<br />
== Links ==<br />
* [http://github.com/nfjinjing/haskore-guide/tree/master/doc/index.markdown A dummy's guide to Haskore (GIT repository)]<br />
* [http://en.wikipedia.org/wiki/Haskore Wikipedia entry about Haskore]<br />
* [http://users.informatik.uni-halle.de/~thielema/Music/HAL2/ Various Haskore examples for CSound, MIDI, SuperCollider and Haskell-Synthesizer] presented on [http://www.iba-cg.de/haskell.html HAL2] by Henning Thielemann, also see the [http://video.google.de/videoplay?docid=-6594267962912965757&q=hal2+july+2007&total=7&start=0&num=50&so=0&type=search&plindex=3 video of the talk (German)]<br />
<br />
== See also ==<br />
<br />
* [http://haskell.cs.yale.edu/euterpea/ Euterpea] is the successor of Haskore.<br />
<br />
<br />
[[Category:Music]]<br />
[[Category:Packages]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Haskore&diff=58565Haskore2014-07-14T10:08:16Z<p>Lemming: /* Links */ Euterpea</p>
<hr />
<div>[http://www.haskell.org/haskore/ Haskore] is a set of Haskell modules for creating, analysing and manipulating music.<br />
Music can be made audible through various back-ends. (See below.)<br />
A more recent, but less stable version, is available as [[Darcs]] repository at http://code.haskell.org/haskore/revised/.<br />
<br />
==Features==<br />
<br />
===Example===<br />
<br />
To get an impression how intuitive music composition with Haskore is, see the following example code (runs with revised Haskore):<br />
<haskell><br />
chords =<br />
(c 0 qn () =:= e 0 qn () =:= g 0 qn ()) +:+<br />
(c 0 qn () =:= f 0 qn () =:= a 0 qn ()) +:+<br />
(d 0 qn () =:= g 0 qn () =:= b 0 qn ())<br />
<br />
song =<br />
MidiMusic.fromMelodyNullAttr MidiMusic.AcousticGrandPiano<br />
(Music.transpose (-48) (Music.changeTempo 3 chords))<br />
</haskell><br />
<br />
The <hask>(=:=)</hask> means parallel composition and<br />
<hask>(+:+)</hask> means serial composition of musical objects.<br />
<br />
===Backends===<br />
<br />
Ideally you can compose a song once in Haskore, and then play it by several back-ends.<br />
Practically this is more difficult, since all back-ends have different functionality (otherwise there wouldn't be so many).<br />
<br />
These back-ends are currently supported:<br />
* [[MIDI]] (both file and realtime)<br />
* [[CSound]]<br />
* [[SuperCollider]]<br />
* [[Synthesizer|Audio files]] rendered by pure Haskell code.<br />
<br />
ToDo:<br />
* Notation output (Lilypond, partially done in CAEC, see below).<br />
<br />
==Community==<br />
<br />
There is no Haskore related mailing list, but Haskore related discussion is very welcome at the [[Haskell art]] mailing list.<br />
<br />
==Getting started==<br />
<br />
=== Platforms ===<br />
<br />
The core Haskore can run on both Linux and Windows.<br />
Only various back-ends and real-time functionality are critical.<br />
So far, real-time playback and use of [[SuperCollider]] is only usable on Linux.<br />
<br />
In future Haskore should consist of a small core for music composition, analysis and manipulation<br />
and separate packages for connecting to various back-ends and separated real-time stuff.<br />
The splitting made some progress, but is still not at its end.<br />
<br />
<!--<br />
==== UNIX/Linux ====<br />
<br />
The original Haskore was mainly developed on Windows,<br />
whereas the revised version was developed mainly in Linux.<br />
So least hassle is currently caused on Linux.<br />
<br />
==== Windows ====<br />
<br />
* http://www.haskell.org/pipermail/haskell-cafe/2008-June/043905.html<br />
* http://www.haskell.org/pipermail/haskell-cafe/2008-August/045911.html - Some hacks to get Haskore running on Windows quickly. The right thing to do would be to factor out the real-time stuff, since it is in general hard to port.<br />
--><br />
<br />
=== Installation using cabal ===<br />
<br />
(There are more detailed installation instructions [http://github.com/nfjinjing/haskore-guide/tree/master/doc/install.markdown here], if the following does not work)<br />
<br />
Prerequisites: You should be able to fetch a package using [[Darcs]] and configure/build/install it using [[Cabal/How_to_install_a_Cabal_package|cabal]].<br />
<br />
Step 0. Since it is the most convenient way of installation, try to install as many as possible packages from [[Hackage]] using cabal-install. Not all packages are available on Hackage because of their experimental state.<br />
<br />
cabal install midi # this will also install non-negative, event-list<br />
cabal install data-accessor<br />
cabal install markov-chain<br />
<br />
Step 1. Install the remaining packages such that at the end the following packages are installed:<br />
<br />
non-negative, event-list, data-accessor, markov-chain, midi, haskore<br />
<br />
If cabal-install worked, there should only <code>haskore</code> be left for installation.<br />
<br />
Step 2. Choose a folder where some haskell packages can be stored.<br />
<br />
Step 3. Get the packages. That is, for each PACKAGE call<br />
<br />
darcs get http://code.haskell.org/PACKAGE<br />
or<br />
darcs get http://code.haskell.org/~thielema/PACKAGE<br />
<br />
Step 4. Build and install the packages that you got by darcs. For each PACKAGE (in the order of above)<br />
<br />
cd PACKAGE<br />
runhaskell Setup.lhs configure (--prefix=/usr/local --user)<br />
runhaskell Setup.lhs build<br />
runhaskell Setup.lhs install<br />
<br />
Step 5. On Linux you may also wish to use SuperCollider.<br />
If you are uncertain, if it is worth the trouble, then listen to the examples given in the [[#Links|Links]] section.<br />
SuperCollider support requires installation of the packages <code>haskore-realtime</code> and <code>haskore-supercollider</code> in the way that is described above.<br />
<br />
Step 6. To get something to listen follow the hints in the [http://code.haskell.org/haskore/revised/Readme Readme] file of the <code>haskore</code> package.<br />
<br />
==Projects==<br />
<br />
A lot of projects were initiated that use the Haskore framework or something in the spirit of Haskore.<br />
This page may help to keep an overview of all projects.<br />
All maintainers of Haskore related projects are encouraged to add their project here and keep the references up to date.<br />
<br />
{|<br />
| [http://www.techfak.uni-bielefeld.de/ags/pi/lehre/AuDIWS02/musik/ AuDi] || Peter Steffen || Course material for Algorithms and Data Structures I - A formula language for music ("Algorithmen und Datenstrukturen I - Eine Formelsprache fuer Musik")<br />
|-<br />
| [http://www.mpi-sb.mpg.de/~ratschan/autotrack/ AutoTrack] || Stefan Ratschan || A tool for creating practizing and demo tracks from chord charts. You feed the program with a chord chart, set the desired style (jazz, bossa, etc.), tempo, key etc. and it produces a simple MIDI file containing an according bass and drum track. Includes a lot of examples.<br />
|-<br />
| [http://code.haskell.org/haskore/revised/related/etude/ CAEC] || Matt Munz || Computer-Aided Etude Composition in Haskell<br />
|-<br />
| [http://code.haskell.org/haskore/revised/ Design experiments] || Henning Thielemann || Test of several changes of Haskore's design targetting at more flexibility and consistency<br />
|-<br />
| [http://www.netsoc.tcd.ie/~bermo/4ba3/report.pdf Emile] || Adam Bermingham || Eight-Bar Melody Generation in Haskell. Automatic composition based on two initial bars<br />
|-<br />
| [http://www.imn.htwk-leipzig.de/~waldmann/ Gore] || Johannes Waldmann || Convert a melody description in a string into the Haskore Music data structure. Thus simple melodies can be written much more condensed.<br />
|-<br />
| [http://meltin.net/hacks/haskell/ HasChorus] || Martin Schwenke || A set of Haskell modules written on top of Haskore to make it easier to sequence simple, repetitive music<br />
|-<br />
| [http://www.idiap.ch/~paiement/ Jazkore] || Jean-François Paiement || A model of melodic jazz improvisation in functional programming<br />
|-<br />
| Lilypond back-end || Jeffrey R. Lewis || A back-end for Haskore to produce Lilypond notation files.<br />
|-<br />
| [http://www.haskell.org/pipermail/haskell-cafe/2006-September/018144.html Microtonal music] || Magnus Jonsson || This is not Haskore related, though integration into Haskore would be nice<br />
|-<br />
| [http://haskell.cs.yale.edu/yale/papers/polymedia/hudak-RR-1259.pdf Polymorphic Temporal Media] || Paul Hudak || An Algebraic Theory of Polymorphic Temporal Media - A generalization of Haskore Music and MDL as well as Fran and FAL animation<br />
|-<br />
| [http://www.cafepress.com/haskore.13482964 T-shirt] || Fritz Ruehr || Haskore T-Shirt featuring the 8 laws of polymorphic temporal media<br />
|}<br />
<br />
== Papers ==<br />
<br />
* Paul Hudak: [http://haskell.cs.yale.edu/yale/papers/polymedia/hudak-RR-1259.pdf An Algebraic Theory of Polymorphic Temporal Media - A generalization of Haskore Music and MDL as well as Fran and FAL animation]<br />
* Henning Thielemann: [http://dafx04.na.infn.it/WebProc/Proc/P_201.pdf Audio Processing using Haskell]<br />
<br />
== Links ==<br />
* [http://github.com/nfjinjing/haskore-guide/tree/master/doc/index.markdown A dummy's guide to Haskore (GIT repository)]<br />
* [http://en.wikipedia.org/wiki/Haskore Wikipedia entry about Haskore]<br />
* [http://users.informatik.uni-halle.de/~thielema/Music/HAL2/ Various Haskore examples for CSound, MIDI, SuperCollider and Haskell-Synthesizer] presented on [http://www.iba-cg.de/haskell.html HAL2] by Henning Thielemann, also see the [http://video.google.de/videoplay?docid=-6594267962912965757&q=hal2+july+2007&total=7&start=0&num=50&so=0&type=search&plindex=3 video of the talk (German)]<br />
<br />
<br />
== See also ==<br />
<br />
* [http://haskell.cs.yale.edu/euterpea/ Euterpea] is the successor of Haskore.<br />
<br />
<br />
[[Category:Music]]<br />
[[Category:Packages]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Live-Sequencer&diff=58564Live-Sequencer2014-07-14T10:05:36Z<p>Lemming: links to MIDI and Haskore</p>
<hr />
<div>Live-Sequencer does the following:<br />
An editor shows a textual description of music (like [[Haskore]]),<br />
an interpreter computes and emits a stream of [[MIDI]] events via [[ALSA]].<br />
While doing so it highlights active terms and shows the result of the term reductions.<br />
The nice thing is, that the user can change the program while it is performed.<br />
Additionally modules can be altered via a web interface.<br />
This way several people can take part in the composition.<br />
However they need to have video and audio access to the running sequencer<br />
in order to see and hear how their parts fit into the overall composition.<br />
<br />
We address two applications:<br />
* interactive multi-user programmed music composition<br />
* education of how functional programs are interpreted<br />
<br />
== Resources ==<br />
<br />
* Installation from Hackage: {{HackagePackage|id=live-sequencer}}<br />
* Bug-Tracker: http://dfa.imn.htwk-leipzig.de/bugzilla/describecomponents.cgi?product=live-sequencer<br />
* Johannes' Git repository - the main repository:<br />
** Direct access: <code>git clone git://dfa.imn.htwk-leipzig.de/srv/git/seq/</code><br />
** Web frontend: http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=seq.git;a=tree<br />
* Henning's Git repository with the cutting edge features:<br />
** git clone http://code.haskell.org/~thielema/livesequencer/<br />
* some example songs:<br />
** http://code.haskell.org/~thielema/livesequencer-example/<br />
<br />
== Papers ==<br />
<br />
* Henning Thielemann: [http://arxiv.org/abs/1202.4269 Live-Musikprogrammierung in Haskell], Arbeitstagung Programmiersprachen ATPS 2012 (German)<br />
* Henning Thielemann: [http://arxiv.org/abs/1303.5768 Live music programming in Haskell], Linux Audio Conference LAC 2013<br />
<br />
== Demonstrations ==<br />
<br />
* [http://www.youtube.com/watch?v=88jK162l6mE kling klong]<br />
* [http://www.youtube.com/watch?v=sXywCHR9WwE electronical menu]<br />
* [http://www.youtube.com/watch?v=-fmxHM69zgI Tausend Sterne sind ein Dom] (engl. "Thousand stars are a cathedral")<br />
* [http://www.youtube.com/watch?v=O5k0wUh0lj8 Glorious Kingdom] (Gospel)<br />
* [http://www.youtube.com/watch?v=0EQCgi5qa3E Alta trinita beata] (featuring speech synthesis)<br />
* [http://www.youtube.com/watch?v=Sk-NtRYqVy4 Drei Chinesen mit dem Kontrabass] (featuring speech synthesis)<br />
<br />
[[Category:Music]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Live-Sequencer&diff=58563Live-Sequencer2014-07-14T10:04:14Z<p>Lemming: /* Demonstrations */ Alta trinita beata, Drei Chinesen mit dem Kontrabass</p>
<hr />
<div>Live-Sequencer does the following:<br />
An editor shows a textual description of music (like Haskore),<br />
an interpreter computes and emits a stream of MIDI events via [[ALSA]].<br />
While doing so it highlights active terms and shows the result of the term reductions.<br />
The nice thing is, that the user can change the program while it is performed.<br />
Additionally modules can be altered via a web interface.<br />
This way several people can take part in the composition.<br />
However they need to have video and audio access to the running sequencer<br />
in order to see and hear how their parts fit into the overall composition.<br />
<br />
We address two applications:<br />
* interactive multi-user programmed music composition<br />
* education of how functional programs are interpreted<br />
<br />
== Resources ==<br />
<br />
* Installation from Hackage: {{HackagePackage|id=live-sequencer}}<br />
* Bug-Tracker: http://dfa.imn.htwk-leipzig.de/bugzilla/describecomponents.cgi?product=live-sequencer<br />
* Johannes' Git repository - the main repository:<br />
** Direct access: <code>git clone git://dfa.imn.htwk-leipzig.de/srv/git/seq/</code><br />
** Web frontend: http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=seq.git;a=tree<br />
* Henning's Git repository with the cutting edge features:<br />
** git clone http://code.haskell.org/~thielema/livesequencer/<br />
* some example songs:<br />
** http://code.haskell.org/~thielema/livesequencer-example/<br />
<br />
== Papers ==<br />
<br />
* Henning Thielemann: [http://arxiv.org/abs/1202.4269 Live-Musikprogrammierung in Haskell], Arbeitstagung Programmiersprachen ATPS 2012 (German)<br />
* Henning Thielemann: [http://arxiv.org/abs/1303.5768 Live music programming in Haskell], Linux Audio Conference LAC 2013<br />
<br />
== Demonstrations ==<br />
<br />
* [http://www.youtube.com/watch?v=88jK162l6mE kling klong]<br />
* [http://www.youtube.com/watch?v=sXywCHR9WwE electronical menu]<br />
* [http://www.youtube.com/watch?v=-fmxHM69zgI Tausend Sterne sind ein Dom] (engl. "Thousand stars are a cathedral")<br />
* [http://www.youtube.com/watch?v=O5k0wUh0lj8 Glorious Kingdom] (Gospel)<br />
* [http://www.youtube.com/watch?v=0EQCgi5qa3E Alta trinita beata] (featuring speech synthesis)<br />
* [http://www.youtube.com/watch?v=Sk-NtRYqVy4 Drei Chinesen mit dem Kontrabass] (featuring speech synthesis)<br />
<br />
[[Category:Music]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Live-Sequencer&diff=58562Live-Sequencer2014-07-14T10:01:46Z<p>Lemming: LAC 2013 paper</p>
<hr />
<div>Live-Sequencer does the following:<br />
An editor shows a textual description of music (like Haskore),<br />
an interpreter computes and emits a stream of MIDI events via [[ALSA]].<br />
While doing so it highlights active terms and shows the result of the term reductions.<br />
The nice thing is, that the user can change the program while it is performed.<br />
Additionally modules can be altered via a web interface.<br />
This way several people can take part in the composition.<br />
However they need to have video and audio access to the running sequencer<br />
in order to see and hear how their parts fit into the overall composition.<br />
<br />
We address two applications:<br />
* interactive multi-user programmed music composition<br />
* education of how functional programs are interpreted<br />
<br />
== Resources ==<br />
<br />
* Installation from Hackage: {{HackagePackage|id=live-sequencer}}<br />
* Bug-Tracker: http://dfa.imn.htwk-leipzig.de/bugzilla/describecomponents.cgi?product=live-sequencer<br />
* Johannes' Git repository - the main repository:<br />
** Direct access: <code>git clone git://dfa.imn.htwk-leipzig.de/srv/git/seq/</code><br />
** Web frontend: http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=seq.git;a=tree<br />
* Henning's Git repository with the cutting edge features:<br />
** git clone http://code.haskell.org/~thielema/livesequencer/<br />
* some example songs:<br />
** http://code.haskell.org/~thielema/livesequencer-example/<br />
<br />
== Papers ==<br />
<br />
* Henning Thielemann: [http://arxiv.org/abs/1202.4269 Live-Musikprogrammierung in Haskell], Arbeitstagung Programmiersprachen ATPS 2012 (German)<br />
* Henning Thielemann: [http://arxiv.org/abs/1303.5768 Live music programming in Haskell], Linux Audio Conference LAC 2013<br />
<br />
== Demonstrations ==<br />
<br />
* [http://www.youtube.com/watch?v=88jK162l6mE kling klong]<br />
* [http://www.youtube.com/watch?v=sXywCHR9WwE electronical menu]<br />
* [http://www.youtube.com/watch?v=-fmxHM69zgI Tausend Sterne sind ein Dom] (engl. "Thousand stars are a cathedral")<br />
* [http://www.youtube.com/watch?v=O5k0wUh0lj8 Glorious Kingdom] (Gospel)<br />
<br />
[[Category:Music]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Embedded_domain_specific_language&diff=58561Embedded domain specific language2014-07-14T09:58:36Z<p>Lemming: /* Examples of Domain Specific Languages */ use HackagePackage template</p>
<hr />
<div>'''Embedded Domain Specific Language''' means that you embed a [http://en.wikipedia.org/wiki/Domain_specific_language Domain specific language] in a language like Haskell.<br />
E.g. using the [http://cryp.to/funcmp/ Functional MetaPost library] you can write Haskell expressions, which are then translated to MetaPost, MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell.<br />
<br />
<br />
== Degree of embedding ==<br />
<br />
There are two major degrees of embedding:<br />
<br />
* Shallow embedding: All Haskell operations immediately translate to the target language. E.g. the Haskell expression <hask>a+b</hask> is translated to a <hask>String</hask> like <hask>"a + b"</hask> containing that target language expression.<br />
* Deep embedding: Haskell operations only build an interim Haskell data structure that reflects the expression tree. E.g. the Haskell expression <hask>a+b</hask> is translated to the Haskell data structure <hask>Add (Var "a") (Var "b")</hask>. This structure allows transformations like optimizations before translating to the target language.<br />
<br />
<br />
== Discussion of common problems ==<br />
<br />
[[Sharing]] and [http://en.wikipedia.org/wiki/Recursion recursion] are common problems when implementing DSLs.<br />
Often some kind of [[observable sharing]] is requested<br />
that requires a deep embedding.<br />
<br />
* Oleg in Haskell-Cafe about [http://www.haskell.org/pipermail/haskell-cafe/2008-February/039639.html Designing DSL with explicit sharing (was: I love purity, but it's killing me)]<br />
* Koen Classen: [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.4053 Observable Sharing for Functional Circuit Description]<br />
* Andy Gill: [http://www.ittc.ku.edu/~andygill/papers/reifyGraph.pdf Type-Safe Observable Sharing]<br />
* Tom Lokhorst [http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video AwesomePrelude presentation (video)]<br />
* Leandro Lisboa Penz [http://lpenz.github.com/articles/hedsl-sharedexpenses/ Haskell eDSL Tutorial - Shared expenses]<br />
* Bruno Oliveira and William Cook: [http://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf Functional Programming with Structured Graphs]<br />
<br />
== Examples of Domain Specific Languages ==<br />
<br />
* Functional MetaPost ({{HackagePackage|id=funcmp}}) is a Haskell frontend to the MetaPost language by John Hobby. Users write their graphics as Haskell programs, which then emit MetaPost code that can be compiled into encapsulated PostScript files and smoothly included into e.g. LaTeX.<br />
<br />
* {{HackagePackage|id=orc}}: Orchestration-style coordination EDSL<br />
<br />
* {{HackagePackage|id=synthesizer-llvm}} provides [[Synthesizer|audio signal processing functions]] that are translated to [[LLVM]] assembly language. This warrants very fast computation. It uses shallow embedding.<br />
<br />
* The {{HackagePackage|id=diagrams-cairo}} package. A full-featured backend for rendering diagrams using the cairo rendering engine. To get started, see Diagrams.Backend.Cairo.CmdLine.<br />
<br />
* {{HackagePackage|id=Workflow}}: library for transparent execution of interruptible computations<br />
<br />
* [http://www.yesodweb.com/book/templates#file253-synopsis Hamlet, Julius, Cassius and Lucius] are languages embedded in the [http://www.yesodweb.com/ Yesod framework]<br />
<br />
== More to read/view ==<br />
<br />
* [http://skillsmatter.com/podcast/scala/haskell-for-embedded-domain-specific-languages Haskell for embedded domain-specific languages] (podcast)<br />
* [[Research papers/Domain specific languages]]<br />
* [http://donsbot.wordpress.com/2007/03/10/practical-haskell-shell-scripting-with-error-handling-and-privilege-separation/ Practical Haskell: shell scripting with error handling and privilege separation] (blog article)<br />
<br />
<br />
<br />
[[Category:Glossary]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Embedded_domain_specific_language&diff=58560Embedded domain specific language2014-07-14T09:56:26Z<p>Lemming: /* Examples of Domain Specific Languages */ synthesizer-llvm</p>
<hr />
<div>'''Embedded Domain Specific Language''' means that you embed a [http://en.wikipedia.org/wiki/Domain_specific_language Domain specific language] in a language like Haskell.<br />
E.g. using the [http://cryp.to/funcmp/ Functional MetaPost library] you can write Haskell expressions, which are then translated to MetaPost, MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell.<br />
<br />
<br />
== Degree of embedding ==<br />
<br />
There are two major degrees of embedding:<br />
<br />
* Shallow embedding: All Haskell operations immediately translate to the target language. E.g. the Haskell expression <hask>a+b</hask> is translated to a <hask>String</hask> like <hask>"a + b"</hask> containing that target language expression.<br />
* Deep embedding: Haskell operations only build an interim Haskell data structure that reflects the expression tree. E.g. the Haskell expression <hask>a+b</hask> is translated to the Haskell data structure <hask>Add (Var "a") (Var "b")</hask>. This structure allows transformations like optimizations before translating to the target language.<br />
<br />
<br />
== Discussion of common problems ==<br />
<br />
[[Sharing]] and [http://en.wikipedia.org/wiki/Recursion recursion] are common problems when implementing DSLs.<br />
Often some kind of [[observable sharing]] is requested<br />
that requires a deep embedding.<br />
<br />
* Oleg in Haskell-Cafe about [http://www.haskell.org/pipermail/haskell-cafe/2008-February/039639.html Designing DSL with explicit sharing (was: I love purity, but it's killing me)]<br />
* Koen Classen: [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.4053 Observable Sharing for Functional Circuit Description]<br />
* Andy Gill: [http://www.ittc.ku.edu/~andygill/papers/reifyGraph.pdf Type-Safe Observable Sharing]<br />
* Tom Lokhorst [http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video AwesomePrelude presentation (video)]<br />
* Leandro Lisboa Penz [http://lpenz.github.com/articles/hedsl-sharedexpenses/ Haskell eDSL Tutorial - Shared expenses]<br />
* Bruno Oliveira and William Cook: [http://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf Functional Programming with Structured Graphs]<br />
<br />
== Examples of Domain Specific Languages ==<br />
<br />
* [http://hackage.haskell.org/package/funcmp Functional MetaPost] is a Haskell frontend to the MetaPost language by John Hobby. Users write their graphics as Haskell programs, which then emit MetaPost code that can be compiled into encapsulated PostScript files and smoothly included into e.g. LaTeX. <br />
<br />
* [http://hackage.haskell.org/package/orc orc]: Orchestration-style coordination EDSL<br />
<br />
* {{HackagePackage|id=synthesizer-llvm}} provides [[Synthesizer|audio signal processing functions]] that are translated to [[LLVM]] assembly language. This warrants very fast computation. It uses shallow embedding.<br />
<br />
* [http://hackage.haskell.org/package/diagrams-cairo The diagrams-cairo package]. A full-featured backend for rendering diagrams using the cairo rendering engine. To get started, see Diagrams.Backend.Cairo.CmdLine.<br />
<br />
* [http://hackage.haskell.org/package/Workflow Workflow]: library for transparent execution of interruptible computations<br />
<br />
* [http://www.yesodweb.com/book/templates#file253-synopsis Hamlet, Julius, Cassius and Lucius] are languages embedded in the [http://www.yesodweb.com/ Yesod framework]<br />
<br />
== More to read/view ==<br />
<br />
* [http://skillsmatter.com/podcast/scala/haskell-for-embedded-domain-specific-languages Haskell for embedded domain-specific languages] (podcast)<br />
* [[Research papers/Domain specific languages]]<br />
* [http://donsbot.wordpress.com/2007/03/10/practical-haskell-shell-scripting-with-error-handling-and-privilege-separation/ Practical Haskell: shell scripting with error handling and privilege separation] (blog article)<br />
<br />
<br />
<br />
[[Category:Glossary]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=58307Template:Main/Events2014-06-09T15:40:12Z<p>Lemming: move ZuriHac and Budapest Hackathon to Recent Events</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
<br />
;[http://iba-cg.de/hal9.html HaL-9]<br />
:June 20, 2014, Halle, Germany<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[[ZuriHac2014|ZuriHac 2014]]<br />
:June 6-8, 2014, Zurich, Switzerland<br />
<br />
;[[BudapestHackathon2014|Budapest Hackathon 2014]]<br />
:May 31 - June 1, 2014, Budapest, Hungary<br />
<br />
;[[Hac NYC]] <br />
:April 4-6, 2014, New York City, US<br />
<br />
;[http://skillsmatter.com/event/scala/functional-programming-exchange-1819 Functional Programming eXchange 2014] <br />
:March 14, 2014, London, UK<br />
<br />
; Well-Typed's introductory and advanced [http://www.well-typed.com/services_training Haskell courses]<br />
:February 10-11 (Introductory) and February 12-13 (Advanced), 2014, London, UK<br />
<br />
;[http://staff.science.uva.nl/~grelck/nl-fp-day-2014.html NL-FP day 2014] <br />
:January 10, 2014, Amsterdam, NLD</div>Lemminghttps://wiki.haskell.org/index.php?title=Haskell_art&diff=58089Haskell art2014-05-15T11:16:42Z<p>Lemming: link to Gmane</p>
<hr />
<div>There is a [http://lurk.org/groups/haskell-art/ hybrid web forum/mailing list] for discussion of doing art with Haskell.<br />
The posts about music dominate so far, but this is not intended.<br />
<br />
The Haskell-art archive can also be viewed at<br />
[http://news.gmane.org/gmane.comp.lang.haskell.art Gmane].<br />
<br />
[[Category:Music]]<br />
[[Category:Community]]</div>Lemminghttps://wiki.haskell.org/index.php?title=FARM&diff=57981FARM2014-04-29T09:05:06Z<p>Lemming: redirect to Conferences article</p>
<hr />
<div>#Redirect[[Conferences#International_Workshop_on_Functional_Art.2C_Music.2C_Modelling_and_Design_.28FARM.29]]<br />
<br />
[[Category:Music]]<br />
[[Category:Community]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Conferences&diff=57980Conferences2014-04-29T09:04:15Z<p>Lemming: FARM</p>
<hr />
<div>Haskell programmers publish a great deal of [[Research papers|research]]<br />
at conferences, which are also great places to meet and discuss <br />
Haskell and its future. The following is a list of some of the<br />
conferences at which Haskellers and their research appears.<br />
<br />
For a calendar-like interface, see [http://www.unsafeperformio.com/confs.php Andy Gill's page].<br />
<br />
== The Haskell Symposium ==<br />
<br />
* [http://haskell.org/haskell-symposium/ The Haskell Symposium].<br />
<br />
The Haskell Symposium is an annual symposium organized in affiliation with<br />
the International Conference on Functional Programming (ICFP). The<br />
workshop is sponsored by the Association for Computing Machinery (ACM)<br />
under the aegis of the ACM Special Interest Group on Programming<br />
Languages (SIGPLAN).<br />
<br />
The purpose of the Haskell Symposium is to discuss experience with<br />
Haskell, and future developments for the language. The scope of the<br />
symposium includes all aspects of the design, semantics, theory,<br />
application, implementation, and teaching of Haskell.<br />
<br />
== The International Conference on Functional Programming (ICFP) ==<br />
<br />
* [http://www.cs.luc.edu/icfp/ The International Conference on Functional Programming (ICFP)]<br />
<br />
ICFP (International Conference on Functional Programming) is an annual<br />
programming language conference. It is sponsored by the Association for<br />
Computing Machinery under the aegis of the ACM Special Interest Group on<br />
Programming Languages (SIGPLAN), in association with Working Group 2.8<br />
of the International Federation of Information Processing (IFIP).<br />
<br />
== Commercial Users of Functional Programming (CUFP) ==<br />
<br />
* [http://www.galois.com/cufp/ Commercial Users of Functional Programming Workshop]<br />
<br />
The goal of CUFP is to build a community for users of functional<br />
programming languages and technology, be they using functional languages<br />
in their professional lives, in an open source project (other than<br />
implementation of functional languages), as a hobby, or any combination<br />
thereof. In short: anyone who uses functional programming as a means,<br />
but not an end<br />
<br />
== International Workshop on Functional Art, Music, Modelling and Design (FARM) ==<br />
<br />
* [http://functional-art.org/ FARM]<br />
<br />
It gathers together people who are harnessing functional techniques in the pursuit of creativity and expression.<br />
<br />
== International Symposium on Functional and Logic Programming (FLOPS) ==<br />
<br />
* [http://www.org.kobe-u.ac.jp/flops2012/ FLOPS 2012]<br />
<br />
FLOPS is a forum for research on all issues concerning declarative programming, including functional programming and logic programming, and aims to promote cross-fertilization and integration between the two paradigms.<br />
<br />
== Principles of Programming Languages (POPL) ==<br />
<br />
* [http://www.cs.ucsd.edu/popl/07/ Principles of Programming Languages (POPL)]<br />
<br />
== Programming Language Design and Implementation (PLDI) ==<br />
<br />
* [http://research.microsoft.com/conferences/pldi06/ Programming Language Design and Implementation (PLDI)]<br />
<br />
== Implementation of Functional Languages (IFL) ==<br />
<br />
* [http://www.cs.uu.nl/wiki/bin/view/IFL2010/PastFutureAndCurrentEvents Implementation of Functional Languages (IFL)]<br />
<br />
== Practical Aspects of Declarative Languages (PADL) ==<br />
<br />
* [http://www.informatik.uni-kiel.de/~mh/padl07 Practical Applications of Declarative Languages (PADL)]<br />
<br />
== Principles and Practice of Declarative Programming (PPDP) ==<br />
<br />
* [http://www.risc.jku.at/about/conferences/ppdp2010/ Principles and Practice of Declarative Programming (PPDP)]<br />
<br />
== Asian Symposium on Programming Languages and Systems (APLAS) ==<br />
<br />
* [http://www.kb.ecei.tohoku.ac.jp/aplas2006/ Asian Symposium on Programming Languages and Systems (APLAS]<br />
<br />
== Declarative Aspects of Multicore Programming (DAMP) ==<br />
<br />
* [http://www.cs.cmu.edu/~damp Declarative Aspects of Multicore Programming (DAMP)]<br />
<br />
== Types in Language Design and Implementation (TLDI) ==<br />
<br />
* [http://www.cs.berkeley.edu/%7Enecula/tldi07/ Types in Language Design and Implementation (TLDI)]<br />
<br />
== Trends in Functional Programming (TFP) ==<br />
<br />
* [http://www.tifp.org/ Trends in Functional Programming]<br />
<br />
== Principles, Logics, and Implementations of High-Level Programming Languages (PLI) ==<br />
<br />
* [http://pli2002.cs.brown.edu/ PLI]<br />
<br />
== Types in Compilation Workshop (TIC) ==<br />
<br />
* [http://www.cs.cmu.edu/~crary/tic00/ Types in Compilation (TIC)]<br />
<br />
== Practical Aspects of High-level Parallel Programming (PAPP) ==<br />
<br />
* [http://f.loulergue.free.fr/PAPP2007/index.html Practical Aspects of High-level Parallel Programming]<br />
<br />
== Federated Conference on Rewriting, Deduction, and Programming (RDP) ==<br />
<br />
* [http://www.lsv.ens-cachan.fr/rdp07/ Federated Conference on Rewriting, Deduction, and Programming]<br />
<br />
== Typed Lambda Calculi and Applications (TLCA) ==<br />
<br />
* [http://www.lsv.ens-cachan.fr/rdp07/tlca.html Typed Lambda Calculi and Applications (TLCA '07)]<br />
<br />
== International Workshop on Functional and Declarative Programming in Education ==<br />
<br />
* [http://www.informatik.uni-kiel.de/~mh/publications/reports/fdpe02/ FDPE]<br />
<br />
== Advanced Functional Programming Spring School (AFP) ==<br />
<br />
* [http://www.cs.ut.ee/afp04/ Advanced Functional Programming: 5th International School]<br />
<br />
== Integrated Formal Methods (IFM) ==<br />
<br />
* [http://www.softeng.ox.ac.uk/ifm2007/ Integrated Formal Methods 2007]<br />
<br />
== UTP'07 at IFM: Unifying Theories of Programming ==<br />
<br />
* [http://www.ifm2007.org Unifying Theories of Programming]<br />
<br />
== Systems Software Verification (SSV) ==<br />
<br />
* [http://nicta.com.au/ssv08/ Systems Software Verification Workshop]<br />
<br />
Please add more Haskell-related conferences as they appear.<br />
<br />
<br />
<br />
[[Category:Events]]</div>Lemminghttps://wiki.haskell.org/index.php?title=FARM&diff=57979FARM2014-04-29T09:00:38Z<p>Lemming: initial text taken from FARM homepage</p>
<hr />
<div>[http://functional-art.org/ FARM] means the ACM SIGPLAN International Workshop on Functional Art, Music, Modelling and Design.<br />
It gathers together people who are harnessing functional techniques in the pursuit of creativity and expression.<br />
<br />
[[Category:Music]]<br />
[[Category:Community]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=57739Template:Main/Events2014-04-02T22:03:14Z<p>Lemming: link to HaL-9 web-page</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
<br />
;[[Hac NYC]] <br />
:April 4-6, 2014, New York City, US<br />
<br />
;[[ZuriHac2014|ZuriHac 2014]]<br />
:June 6-8, 2014, Zurich, Switzerland<br />
<br />
;[http://iba-cg.de/hal9.html HaL-9]<br />
:June 20, 2014, Halle, Germany<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands<br />
<br />
<div class="subtitle">Recent Events</div><br />
;[http://skillsmatter.com/event/scala/functional-programming-exchange-1819 Functional Programming eXchange 2014] <br />
:March 14, 2014, London, UK<br />
<br />
; Well-Typed's introductory and advanced [http://www.well-typed.com/services_training Haskell courses]<br />
:February 10-11 (Introductory) and February 12-13 (Advanced), 2014, London, UK<br />
<br />
;[http://staff.science.uva.nl/~grelck/nl-fp-day-2014.html NL-FP day 2014] <br />
:January 10, 2014, Amsterdam, NLD</div>Lemminghttps://wiki.haskell.org/index.php?title=Template:Main/Events&diff=57666Template:Main/Events2014-03-14T14:04:51Z<p>Lemming: HaL-9</p>
<hr />
<div><!-- NOTE: When adding a new event, please also remove "Recent Events" older than 6 months. Please also keep this comment. --><br />
<div class="subtitle">Upcoming Events</div><br />
<br />
;[http://skillsmatter.com/event/scala/functional-programming-exchange-1819 Functional Programming eXchange 2014] <br />
:March 14, 2014, London, UK<br />
<br />
;[[Hac NYC]] <br />
:April 4-6, 2014, New York City, US<br />
<br />
;[[ZuriHac2014|ZuriHac 2014]]<br />
:June 6-8, 2014, Zurich, Switzerland<br />
<br />
;HaL-9<br />
:June 20, 2014, Halle, Germany<br />
<br />
;[http://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell 6th Utrecht Summerschool on Applied Functional Programming]<br />
:July 7-18, 2014, Utrecht, The Netherlands<br />
<br />
<div class="subtitle">Recent Events</div><br />
; Well-Typed's introductory and advanced [http://www.well-typed.com/services_training Haskell courses]<br />
:February 10-11 (Introductory) and February 12-13 (Advanced), 2014, London, UK<br />
<br />
;[http://staff.science.uva.nl/~grelck/nl-fp-day-2014.html NL-FP day 2014] <br />
:January 10, 2014, Amsterdam, NLD<br />
<br />
;[http://fpdays.net/fpdays2013/ FP Days] <br />
:October 24-25, 2013, Cambdrige, UK</div>Lemminghttps://wiki.haskell.org/index.php?title=Parallelism_vs._Concurrency&diff=57657Parallelism vs. Concurrency2014-03-09T09:47:23Z<p>Lemming: distributed-net contains aspects of both parallelism and concurrency</p>
<hr />
<div>The term '''Parallelism''' refers to techniques to make programs faster by performing several computations in parallel.<br />
This requires hardware with multiple processing units.<br />
In many cases the sub-computations are of the same structure, but this is not necessary.<br />
Graphic computations on a GPU are parallelism.<br />
Key problem of parallelism is to reduce data dependencies<br />
in order to be able to perform computations on independent computation units<br />
with minimal communication between them.<br />
To this end it can be even an advantage to do the same computation twice on different units.<br />
<br />
The term '''Concurrency''' refers to techniques that make program more usable.<br />
Concurrency can be implemented and is used a lot on single processing units,<br />
nonetheless it may benefit from multiple processing units with respect to speed.<br />
If an operating system is called a multi-tasking operating system, this is a synonym for supporting concurrency.<br />
If you can load multiple documents simultaneously in the tabs of your browser and<br />
you can still open menus and perform more actions, this is concurrency.<br />
<br />
If you run distributed-net computations in the background<br />
while working with interactive applications in the foreground,<br />
that is concurrency.<br />
On the other hand dividing a task into packets<br />
that can be computed via distributed-net clients,<br />
this is parallelism.<br />
<br />
== An anecdote from good old Amiga days ==<br />
<br />
Let me tell an anecdote to further sharpen the difference:<br />
Amiga computers were always advertised for their multi-tasking operating system.<br />
However DOS/Windows-3.1 users were never attracted by this advertisement<br />
since they argued that a single CPU cannot be made faster by performing several tasks in an interleaved way.<br />
They were right, but this was not the point: Multitasking allows to avoid that the computer gets bored.<br />
Indeed in the eighties Amiga computers were considered great for raytracing.<br />
However the special graphics and sound hardware in Amiga computers could not help with raytracing.<br />
The important advantage was, that you could perform the graphics rendering concurrently to your daily work (office applications) without noticing the computation load of the raytracing.<br />
Multitasking just assigns the time between your keystrokes to the raytracer.<br />
However multitasking was not possible with most games, office software that eats all the memory or simply crashing applications.<br />
This leads to another confusing area: [[Error vs. Exception]].<br />
<br />
== How to distinguish between Parallelism and Concurrency ==<br />
<br />
* If you need <hask>getNumCapabilities</hask> in your program, then your are certainly programming parallelism.<br />
* If your parallelising efforts make sense on a single processor machine, too, then you are certainly programming concurrency.<br />
<br />
== Warning ==<br />
<br />
Not all programmers agree on the meaning of the terms 'parallelism' and 'concurrency'.<br />
They may define them in different ways or do not distinguish them at all.<br />
<br />
== See also ==<br />
<br />
* Note of Simon Marlow in [http://www.haskell.org/pipermail/haskell-cafe/2008-September/047312.html Haskell-Cafe] about the distinction of parallelism and concurrency<br />
* GHC mutterings on [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ Parallelism /= Concurrency]<br />
<br />
[[Category:Idioms]]<br />
[[Category:Parallel]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Parallelism_vs._Concurrency&diff=57656Parallelism vs. Concurrency2014-03-09T09:44:52Z<p>Lemming: duplicate computations for reduction of data dependencies</p>
<hr />
<div>The term '''Parallelism''' refers to techniques to make programs faster by performing several computations in parallel.<br />
This requires hardware with multiple processing units.<br />
In many cases the sub-computations are of the same structure, but this is not necessary.<br />
Graphic computations on a GPU are parallelism.<br />
Key problem of parallelism is to reduce data dependencies<br />
in order to be able to perform computations on independent computation units<br />
with minimal communication between them.<br />
To this end it can be even an advantage to do the same computation twice on different units.<br />
<br />
The term '''Concurrency''' refers to techniques that make program more usable.<br />
Concurrency can be implemented and is used a lot on single processing units,<br />
nonetheless it may benefit from multiple processing units with respect to speed.<br />
If an operating system is called a multi-tasking operating system, this is a synonym for supporting concurrency.<br />
If you can load multiple documents simultaneously in the tabs of your browser and<br />
you can still open menus and perform more actions, this is concurrency.<br />
If you run distributed-net computations in the background, that is concurrency.<br />
<br />
== An anecdote from good old Amiga days ==<br />
<br />
Let me tell an anecdote to further sharpen the difference:<br />
Amiga computers were always advertised for their multi-tasking operating system.<br />
However DOS/Windows-3.1 users were never attracted by this advertisement<br />
since they argued that a single CPU cannot be made faster by performing several tasks in an interleaved way.<br />
They were right, but this was not the point: Multitasking allows to avoid that the computer gets bored.<br />
Indeed in the eighties Amiga computers were considered great for raytracing.<br />
However the special graphics and sound hardware in Amiga computers could not help with raytracing.<br />
The important advantage was, that you could perform the graphics rendering concurrently to your daily work (office applications) without noticing the computation load of the raytracing.<br />
Multitasking just assigns the time between your keystrokes to the raytracer.<br />
However multitasking was not possible with most games, office software that eats all the memory or simply crashing applications.<br />
This leads to another confusing area: [[Error vs. Exception]].<br />
<br />
== How to distinguish between Parallelism and Concurrency ==<br />
<br />
* If you need <hask>getNumCapabilities</hask> in your program, then your are certainly programming parallelism.<br />
* If your parallelising efforts make sense on a single processor machine, too, then you are certainly programming concurrency.<br />
<br />
== Warning ==<br />
<br />
Not all programmers agree on the meaning of the terms 'parallelism' and 'concurrency'.<br />
They may define them in different ways or do not distinguish them at all.<br />
<br />
== See also ==<br />
<br />
* Note of Simon Marlow in [http://www.haskell.org/pipermail/haskell-cafe/2008-September/047312.html Haskell-Cafe] about the distinction of parallelism and concurrency<br />
* GHC mutterings on [http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/ Parallelism /= Concurrency]<br />
<br />
[[Category:Idioms]]<br />
[[Category:Parallel]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Package_versioning_policy&diff=57630Package versioning policy2014-02-28T21:44:31Z<p>Lemming: /* Tools */ check-pvp</p>
<hr />
<div>== Rationale ==<br />
<br />
The goal of a versioning system is to inform clients of a package of changes to that package that might affect them, and to provide a way for clients to specify a particular version or range of versions of a dependency that they are compatible with.<br />
<br />
[http://haskell.org/cabal Cabal] provides the raw materials for versioning: it allows packages to specify their own version, and it allows dependencies that specify which versions of the dependent package are acceptable. Cabal will select dependencies based on the constraints.<br />
<br />
What is missing from this picture is a ''policy'' that tells the library developer how to set their version numbers, and tells a client how to write a dependency that means their package will not try to compile against an incompatible dependency. For some time there has been an informal policy in use in the Haskell community, but it became clear that we were running into trouble with incorrectly-specified dependencies and unbuildable packages, so this page is an attempt to formalize the policy.<br />
<br />
== Version numbers ==<br />
<br />
A package version number should have the form ''A.B.C'', and may optionally have any number of additional components, for example 2.1.0.4 (in this case, ''A''=2, ''B''=1, ''C=0''). This policy defines the meaning of the first three components ''A-C'', the other components can be used in any way the package maintainer sees fit.<br />
<br />
Version number ordering is already defined by Cabal as the lexicographic ordering of the components. For example, 2.1 > 1.3, and 2.1.1 > 2.1. (The <tt>Data.Version.Version</tt> type and its <tt>Ord</tt> instance embody this ordering).<br />
<br />
''A.B'' is known as the ''major'' version number, and ''C'' the ''minor'' version number. When a package is updated, the following rules govern how the version number must change relative to the previous version:<br />
<br />
# If any entity was removed, or the types of any entities or the definitions of datatypes or classes were changed, or instances were added or removed, then the new ''A.B'' must be greater than the previous ''A.B''. Note that modifying imports or depending on a newer version of another package may cause extra instances to be exported and thus force a major version change.<br />
# Otherwise, if only new bindings, types, classes or modules (but see below) were added to the interface, then ''A.B'' may remain the same but the new ''C'' must be greater than the old ''C''.<br />
# Otherwise, ''A.B.C'' may remain the same (other version components may change).<br />
<br />
Hence ''A.B.C'' uniquely identifies the API. A client that wants to specify that they depend on a particular version of the API can specify a particular ''A.B.C'' and be sure of getting that API only. For example, <tt>build-depends: mypkg >= 2.1.1 && < 2.1.2</tt>.<br />
<br />
Often a package maintainer wants to add to an API without breaking backwards compatibility, and in that case they can follow the rules of point 2, and increase only ''C''. A client can specify that they are [[Import modules properly|insensitive to additions to the API]] by allowing a range of ''C'' values, e.g. <tt>build-depends: base >= 2.1.1 && < 2.2</tt>.<br />
<br />
=== Deprecation ===<br />
<br />
Deprecated entities (via a DEPRECATED pragma) should probably be counted as removed for the purposes of upgrading the API, because packages that use <tt>-Werror</tt> will be broken by the deprecation.<br />
<br />
=== Adding new modules ===<br />
<br />
Adding new modules might cause an unavoidable name collision in dependent code. However, this is usually pretty unlikely, especially if you keep to your own namespace, so only an increase of the minor version number is required. If, however, your added module name is taken from another package (e.g. when <tt>network-bytestring</tt> was merged into <tt>network</tt>) or is quite general (Data.Set or something similar) then the version increase should be major.<br />
<br />
=== Version tags ===<br />
<br />
The components of the version number must be numbers! Historically Cabal supported version numbers with string tags at the end, e.g. <tt>1.0-beta</tt> This proved not to work well because the ordering for tags was not well defined. Version tags are [https://github.com/haskell/cabal/issues/890 no longer supported] and mostly ignored, however some tools will fail in some circumstances if they encounter them.<br />
<br />
This can sometimes trip you up if you accidentally stumble into using the deprecated tags syntax without realising it, for example a version number with a date like <tt>1.0.2014-01-27</tt> would be interpreted as the version <tt>1.0.2014</tt> with tags <tt>01</tt> and <tt>27</tt>.<br />
<br />
== Dependencies in Cabal ==<br />
<br />
When publishing a Cabal package, you should ensure that your dependencies in the <tt>build-depends</tt> field are accurate. This means specifying not only lower bounds, but also upper bounds on every dependency. <br />
<br />
At some point in the future, Hackage may refuse to accept packages that do not follow this convention. The aim is that before this happens, we will put in place tool support that makes it easier to follow the convention and less painful when dependencies are updated.<br />
<br />
To minimize breakage when new package versions are released, you can use dependencies that are insensitive to minor version changes (e.g. <tt>foo >= 1.2.1 && < 1.3</tt>). However, note that this approach is slightly risky: when a package exports more things than before, there is a chance that your code will fail to compile due to new name-clash errors. The risk from new name clashes may be small, but you are on the safe side if you [[Import modules properly|import identifiers explicitly or using qualification]].<br />
<br />
== Version syntax ==<br />
<br />
Since Cabal 1.6, you can specify an exact API version according to this policy with the special syntax <tt>package == 1.1.4.*</tt> or an API version up to additions with <tt>package == 1.1.*</tt>. The former translates into <tt>package >= 1.1.4 && < 1.1.5</tt>, for example - notice that 1.1.4 ''is'' included, rather than just including 1.1.4.0.<br />
<br />
== Tools ==<br />
<br />
* script to check for API changes in gtk2hs: http://code.haskell.org/gtk2hs/tools/apidiff/<br />
* [http://hackage.haskell.org/package/precis precis] - a simple tool for a first approximation of package API differences, see the [http://www.haskell.org/pipermail/haskell-cafe/2010-April/077023.html announcement]<br />
* {{HackagePackage|id=check-pvp}} is a program that checks for consistency between package dependencies and import style.<br />
<br />
== Related ==<br />
<br />
* [[Sven Moritz Hallberg]], "[[The_Monad.Reader/Issue2/EternalCompatibilityInTheory|Eternal compatibility in theory]]," [[The Monad.Reader]], [[The Monad.Reader/Issue2|Issue 2]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Import_modules_properly&diff=57625Import modules properly2014-02-28T19:50:18Z<p>Lemming: /* See also */ check-pvp on Hackage</p>
<hr />
<div>== Introduction ==<br />
<br />
Haskell has a lot of variants of [[Import|importing]] identifiers from other modules.<br />
However not all of them are as comfortable as they seem to be at the first glance.<br />
We recommend to focus on the following two forms of import:<br />
<haskell><br />
import qualified Very.Special.Module as VSM<br />
import Another.Important.Module (printf, (<|>), )<br />
</haskell><br />
instead of<br />
<haskell><br />
import Very.Special.Module<br />
import Another.Important.Module hiding (open, close, )<br />
</haskell><br />
<br />
There are four different kind of reasons for this.<br />
<br />
* '''Style:''' If you read <hask>printf</hask>, <hask><|></hask> or <hask>VSM.open</hask> in the program you can find out easily where the identifier comes from. In the second case you don't know if these identifiers are from <hask>Very.Special.Module</hask>, <hask>Another.Important.Module</hask> or even other modules. Mind you that grep won't help, because <hask>Very.Special.Module</hask> and <hask>Another.Important.Module</hask> might just re-export other modules. You might guess the origin of <hask>printf</hask> according to its name, but for the infix operator <hask><|></hask> you will certainly have no idea.<br />
* '''Compatibility:''' In the second case, if new identifiers are added to the imported modules they might clash with names of other modules. Thus updating imported modules may break your code. If you import a package A with version a.b.c.d that follows the [[Package versioning policy]] then within versions with the same a.b it is allowed to add identifiers. This means that if you import the suggested way, you can safely specify <code>A >= a.b.c && <a.b+1</code> in your [[Cabal]] file. Otherwise you have to chose the smaller range <code>A >= a.b.c && <a.b.c+1</code>. It may also be that <hask>Another.Important.Module.open</hask> was deprecated when you hid it, and with a module update removing that identifier, your import fails. That is, an identifier that you never needed but only annoyed you, annoys you again, when it was meant to not bother you any longer! The first variant of import does not suffer from these problems.<br />
* '''Correctness:''' I once found a bug in the StorableVector package by converting anonymous imports to explicit imports. I found out that the function <hask>Foreign.Ptr.plusPtr</hask> was imported, although functions from this module always have to calculate with unit "element" not "byte". That is, <hask>advancePtr</hask> must be used instead. Actually, the <hask>reverse</hask> function used <hask>plusPtr</hask> and this was wrong. A misbehaviour could only be observed for sub-vectors and elements with size greater than 1 byte. The test suite did miss that.<br />
* '''Maintenance:''' All too often I find an old module that cannot be compiled any longer since it uses identifiers that do no longer exist. If the module imports implicitly und without qualification I have little chance to find out where the identifiers originally came from, what they meant and how they must be replaced.<br />
<br />
== Exception from the rule ==<br />
<br />
Since the Prelude is intended to be fixed for the future, it should be safe to use the <hask>hiding</hask> clause when importing <hask>Prelude</hask>.<br />
Actually if you do not mention Prelude it will be imported anonymously.<br />
<br />
== Clashing of module name abbreviations ==<br />
<br />
In Haskell it is possible to use the same abbreviation for different modules:<br />
<haskell><br />
import qualified Data.List as List<br />
import qualified Data.List.Extra as List<br />
</haskell><br />
This is discouraged for the same reasons as above:<br />
<br />
* '''Style''': The identifier <hask>List.intercalate</hask> may refer to either <hask>Data.List</hask> or <hask>Data.List.Extra</hask>. The reader of that module has to check these modules in order to find it out.<br />
<br />
* '''Compatibility''': The function <hask>List.intercalate</hask> may be currently defined only in <hask>Data.List.Extra</hask>. However after many people found it useful, it is also added to <hask>Data.List</hask>. Then <hask>List.intercalate</hask> can no longer be resolved.<br />
<br />
== Counter-arguments to explicit import lists ==<br />
<br />
The issue of whether to use explicit import lists is not always clear-cut, however.<br />
Here are some reasons you might not want to do this:<br />
<br />
* Development is slower: almost every change is accompanied by an import list change, especially if you want to keep your code warning-clean.<br />
<br />
* When working on a project with multiple developers, explicit import lists can cause spurious conflicts, since two otherwise-unrelated changes to a file may both require changes to the same import list.<br />
<br />
For these reasons amongst others, the GHC project decided to drop the use of explicit import lists.<br />
We recommend using explicit import lists when importing from other packages,<br />
but not when importing modules within the same package.<br />
<br />
Qualified use of identifiers does not suffer from the above problems.<br />
<br />
== See also ==<br />
<br />
* [[Qualified names]]<br />
<br />
* {{HackagePackage|id=check-pvp}} is a program that checks for consistency between package dependencies and import style.<br />
<br />
{{essay}}<br />
<br />
[[Category:Style]]</div>Lemminghttps://wiki.haskell.org/index.php?title=GHC/FAQ&diff=57565GHC/FAQ2014-02-14T10:07:47Z<p>Lemming: /* Why does linking take so long? */ dynamic linking</p>
<hr />
<div>[[Category:GHC]] [[Category:FAQ]]<br />
Please feel free to add stuff here.<br />
<br />
This page is rather long. We've started to add some sub-headings, but would welcome your help in making it better organised.<br />
<br />
= GHC (Platform-specific Issues) =<br />
<br />
== Porting GHC ==<br />
<br />
=== How do I port GHC to platform X? ===<br />
<br />
There are two distinct possibilities: either<br />
<br />
* The hardware architecture for your system is already supported by GHC, but you're running an OS that isn't supported (or perhaps has been supported in the past, but currently isn't). This is the easiest type of porting job, but it still requires some careful bootstrapping.<br />
<br />
* Your system's hardware architecture isn't supported by GHC. This will be a more difficult port (though by comparison perhaps not as difficult as porting gcc).<br />
<br />
Both ways require you to bootstrap from intermediate HC files: these are the stylised C files generated by GHC when it compiles Haskell source. Basically the idea is to take the HC files for GHC itself to the target machine and compile them with gcc to get a working GHC, and go from there.<br />
<br />
The [http://hackage.haskell.org/trac/ghc/wiki/Building Building Guide] has all the details on how to bootstrap GHC on a new platform.<br />
<br />
<br />
== Linux-related ==<br />
<br />
=== Missing libreadline.so.x Errors ===<br />
<br />
==== I Can't run GHCi on Linux, because it complains about a missing <tt>libreadline.so.3</tt>. ====<br />
<br />
The "correct" fix for this problem is to install the correct package for the particular flavour of Linux on your machine. If this isn't an option, however, there is a hack that might work: make a symbolic link from <tt>libreadline.so.4</tt> to <tt>libreadline.so.3</tt> in <tt>/usr/lib</tt>. We tried this on a SuSE 7.1 box and it seemed to work, but YMMV.<br />
<br />
=== Linking Errors ===<br />
<br />
==== Linking a program causes the following error on Linux: <tt>/usr/bin/ld: cannot open -lgmp: No such file or directory</tt> ====<br />
<br />
The problem is that your system doesn't have the GMP library installed. If this is a RedHat distribution, install the RedHat-supplied gmp-devel package, and the gmp package if you don't already have it. There have been reports that installing the RedHat packages also works for SuSE (SuSE doesn't supply a shared gmp library).<br />
<br />
=== SELinux-related ===<br />
<br />
==== Memory Allocation Errors ====<br />
<br />
If you have SELinux enabled on your system, then GHC may fail with a memory allocation error:<br />
<br />
ghc-6.4.1: internal error: mallocBytesRWX: failed to protect 0x0x1660730<br />
<br />
or maybe<br />
<br />
ghc: internal error: getMBlock: mmap: Permission denied <br />
<br />
The reason for this is that SELinux prevents allocation of writeable/executable memory regions, which GHC needs in order to implement certain parts of the FFI that require dynamic code generation. (See [http://hackage.haskell.org/trac/ghc/ticket/738 this bug report]).<br />
<br />
In GHC 6.4.2 we improved the situation somewhat, but not completely.<br />
<br />
Workarounds:<br />
<br />
* Set <tt>allow_execmem</tt> to 0, with the <tt>setsebool</tt> command.<br />
* do this on a per-program basis, for GHC and GHC-compiled programs. Apparently this is done by:<br />
<br />
<tt>/usr/bin/chcon -t unconfined_execmem_exec_t /path/to/binary/prog</tt><br />
<br />
== Solaris-related ==<br />
<br />
=== Link Errors ===<br />
<br />
==== Solaris users may sometimes get link errors due to libraries needed by GNU Readline. ====<br />
<br />
We suggest you try linking in some combination of the termcap, curses and ncurses libraries, by giving <tt>-ltermcap</tt>, <tt>-lcurses</tt> and <tt>-lncurses</tt> respectively. If you encounter this problem, we would appreciate feedback on it, since we don't fully understand what's going on here.<br />
The build fails in readline.<br />
<br />
It has been reported that if you have multiple versions of the readline library installed on Linux, then this may cause the build to fail. If you have multiple versions of readline, try uninstalling all except the most recent version.<br />
<br />
== Windows-related ==<br />
<br />
=== Heapsize-related Crashes ===<br />
<br />
==== My program that uses a really large heap crashes on Windows. ====<br />
<br />
For utterly horrible reasons, programs that use more than 128Mb of heap won't work when compiled dynamically on Windows (they should be fine statically compiled).<br />
<br />
=== Ctrl-C Not Working ===<br />
<br />
When running GHC under a Cygwin shell on Windows, Ctrl-C sometimes doesn't work. A workaround is to use Ctrl-Break instead. Another workaround is to use the rlwrap program (cygwin package available) to invoke ghci : In addition to proper Ctrl-C, you also get emacs (or vi) key bindings and command history across sessions. <br />
<br />
=== Linking with Visual Studio C++ Code ===<br />
<br />
==== How do I link Haskell with C++ code compiled by Visual Studio? ====<br />
<br />
===== Prerequisites =====<br />
<br />
It is assumed that the reader is familiar with the Haskell <br />
[http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi.html Foreign function interface (FFI)],<br />
and is able to compile Haskell programs with GHC and C++ programs with Visual Studio.<br />
<br />
===== Background =====<br />
<br />
GHC has two modes of code generation. It either compiles Haskell straight into object code<br />
(native mode), or translates Haskell into intermediate C code, and uses a C compiler as backend.<br />
<br />
The Windows distribution of GHC comes bundled with the GCC compiler, which is used as backend.<br />
That's why linking Haskell with Visual C++ is no different from linking GCC-generated code with<br />
the code generated by Visual C++.<br />
<br />
One cannot statically link together object files produced by those two compilers,<br />
but they can be linked dynamically: an executable produced by Visual C++ can invoke a DLL<br />
produced by GCC, and vice versa. Likewise, we can link Haskell with Visual C++ in one of these ways.<br />
<br />
''Note:'' when Haskell becomes able to use Visual C++ as a backend (see [http://hackage.haskell.org/trac/ghc/ticket/989]), we would not need to go via a DLL anymore. Instead, we would simply list<br />
all source files (Haskell and C++) on the command line of GHC.<br />
<br />
===== Invoking a Haskell DLL =====<br />
<br />
====== From a C++ executable ======<br />
<br />
#Make a Haskell DLL as explained in [http://www.haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html#win32-dlls-foreign]<br />
#Make a module definition file, such as<tt><br>LIBRARY Adder<br>EXPORTS<br>&nbsp;&nbsp;&nbsp;&nbsp;adder</tt><br />
#Create an import library using Visual Studio's <tt>lib.exe:<br>lib /DEF:adder.def /OUT:adder.lib</tt><br />
#Link the C++ program against the import library.<br />
<br />
====== From a Haskell executable ======<br />
<br />
#Make a DLL project in Visual Studio. It will create a <tt>.vcproj</tt> and <tt>.sln</tt> files for you. Add your C++ source files to this project. <br />
#Create a <tt>.def</tt> file for your DLL. It might look like<tt><br>LIBRARY MyDLL<br>EXPORTS<br>&nbsp;&nbsp;&nbsp;&nbsp;function1<br>&nbsp;&nbsp;&nbsp;&nbsp;function2<br></tt> where <tt>function1</tt> and <tt>function2</tt> are the names of the C++ functions that you want to invoke from Haskell (there can be more of them, of course), <tt>MyDLL</tt> is the name of your DLL.<br />
#Create an import library that can be used by <tt>ghc:<br>dlltool -d MyDLL.def -l libMyDLL.a</tt> <br />
#Link your Haskell project, adding the library:<tt><br>ghc --make main.hs -optl-lMyDLL -optl-L.<br></tt>''mind the dot at the end of the command line!''<br> (<tt>[http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#forcing-options-through -optl]</tt> switch passes its argument as an option to the linker).<br />
<br />
=== GHCi Hanging Issues ===<br />
<br />
==== GHCi hangs after "Loading package base ... linking ... done." ====<br />
<br />
On a small number of systems GHCi will fail to start, hanging after loading the base package. The "Prelude>" prompt is never reached.<br />
<br />
This is believed to be due to a bug in Windows thought to affect tablet PCs, although the details are not fully understood.<br />
<br />
A workaround is to open a command prompt, enter "chcp 28591" - if this hangs hit Ctrl-C - and then run "ghci". Some users may find this [http://support.microsoft.com/kb/925271 hotfix] useful.<br />
<br />
=== A console window opens when my application is supposed to be GUI only ===<br />
<br />
Windows has several different "subsystems", the default subsystem which the mingw linker uses is console, so that stdout/stderr can be printed on screen and stdin be read from the console window.<br />
<br />
This can be solved by giving the option -optl-mwindows with the compile command:<br />
ghc --make -optl-mwindows MyProgramWithGUI.lhs<br />
With this option, the option -mwindows is passed to the linker.<br />
<br />
Caveat: attempting to read from stdin with -mwindows set may cause a runtime error, any output on stdout/stderr will be lost.<br />
<br />
== .NET/JVM Availability ==<br />
<br />
=== Why isn't GHC available for .NET or on the JVM? ===<br />
<br />
It would make a lot of sense to give GHC a .NET or JVM back end, and it's a<br />
question that comes up regularly. The reason that we haven't done it<br />
here, at GHC HQ, is because it's a more substantial undertaking than<br />
might at first appear (see below). Furthermore, it'd permanently add a<br />
complete new back-end platform for us to maintain. Given our rather<br />
limited development effort, we have so far not bitten<br />
the bullet, and we have no immediate plans to do so.<br />
<br />
It would be a good, well-defined project for someone else to tackle, and<br />
we would love to see it done. There is some good groundwork already done:<br />
<br />
* Ashley Yakeley worked on a [http://sourceforge.net/projects/jvm-bridge/ Haskell-JVM bridge]<br />
<br />
* Sigbjorn Finne did a simple interop implementation ([http://hackage.haskell.org/package/hs-dotnet the hs-dotnet package]) that allows a Haskell program to be compiled to native code (as now) but to call .NET programs via a variant of the FFI. I don't think this work is in active use, and I'd be surprised if it worked out of the box, but it could probably be revived with modest effort<br />
<br />
* Andre Santos and his colleagues at UFPE in Brazil are working on a .NET back end, that generates CLR IL, though I don't know where they are up to.<br />
<br />
* Nigel Perry and Oliver Hunt have a Haskell.NET prototype that works using GHC to compile to Core, and then compiling Core to NET. I'm not sure what stage it is at.<br />
<br />
* GHC.Net would be extra attractive if there was a Visual Studio integration for GHC. Substantial progress on this has been made in 2004 by Simon Marlow, Krasimir Angelov, and Andre Santos and colleagues.<br />
<br />
* Brian Alliet created a patch for GHC called LambdaVM that compiles programs into JVM bytecode. [http://wiki.brianweb.net/LambdaVM/LambdaVM]<br />
<br />
* Not GHC but [[UHC]]: the Jazy backend of UHC generates Java class files to allow Haskell programs to run on the Java Virtual Machine (JVM). Jazy is [http://www.cs.uu.nl/wiki/bin/view/Ehc/UhcJazyDocumentation#2_Status not fully functional yet].<br />
<br />
<br />
There may be others that I don't know of. If anyone wants to join in<br />
this effort, do contact the above folk. And please keep us informed!<br />
<br />
Here's a summary of why it's a non-trivial thing to do (using .NET language, but it mostly applies to the JVM too):<br />
<br />
* The first thing is to generate native CLR Intermediate Language (IL). That's not really hard. Requires thinking about representations for thunks and functions, and it may not be particularly efficient, but it can surely be done. <br />
: An open question is about whether to generate ''verifiable'' IL or not. The trouble here is that Haskell's type system is more expressive than the CLR's in some ways, notably the use of higher-kinded type variables. So, to generate verifiable IL one is bound to need some run-time casts, and it's not clear how to minimise these.<br />
<br />
At first blush this is ''all'' you need do. But it isn't!<br />
<br />
* Next, you need to think about how to inter-operate with .NET libraries. You don't really want to write "foreign import..." for each and every import. You'd like GHC to read the CLR meta-data directly. But there are lots of tricky issues here; see the paper that Mark Shields and I wrote about "Object-oriented style overloading for Haskell".<br />
<br />
* A closely-related question is this: how to make the type systems of Java/.NET and Haskell "line up"? For example, when importing a Java procedure, what is the Haskell type that corresponds to its .NET/JVM type? How do you sub-class a .NET class in Haskell? For example [http://research.microsoft.com/en-us/um/people/simonpj/papers/oo-haskell/index.htm Object-Oriented Style Overloading for Haskell] gives one "take" on the subject, but there are plenty of other possibilities. <br />
<br />
* Now you need to figure out how to implement GHC's primitive operations:<br />
** the I/O monad<br />
** arbitrary precision arithmetic<br />
** concurrency<br />
** exceptions<br />
** finalisers<br />
** stable pointers<br />
** [[Software transactional memory]]<br />
<br />
:: Not all of these are necessary, of course, but many are used in the libraries. The CLR supports many of them (e.g. concurrency) but with a very different cost model.<br />
<br />
* Last, you have to figure out what to do for the libraries. GHC has a pretty large library, and you either have to implement the primops on which the library is based (see previous point), or re-implement it. For example, GHC's implementation of I/O uses mutable state, concurrency, and more besides. For each module, you need to decide either to re-implement it using .NET primitives, or to implement the stuff the module is based on.<br />
<br />
These challenges are mostly broad rather than deep. But to get a<br />
production quality implementation that runs a substantial majority of<br />
Haskell programs "out of the box" requires a decent stab at all of them.<br />
<br />
== Mac OS X-related ==<br />
<br />
=== Linking with GHC ===<br />
<br />
==== Linking with ghc produces <tt>ld: Undefined symbols: _sprintf$LDBLStub ...</tt> ====<br />
<br />
This happens on a PowerPC Mac OS X 10.4 if gcc-3.3 is the default compiler and you try to compile with a ghc that has been built with gcc-4.0. For example:<br />
<br />
$ cat t2.hs <br />
module Main where<br />
main = putStr ("t2: Hello trac 1066 2007-Feb-17 19.48\n")<br />
$ gcc --version<br />
gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1819)<br />
...<br />
$ ghc --make t2.hs<br />
[1 of 1] Compiling Main ( t2.hs, t2.o )<br />
Linking t2 ...<br />
ld: Undefined symbols:<br />
_sprintf$LDBLStub<br />
_fprintf$LDBLStub<br />
_vfprintf$LDBLStub<br />
_sscanf$LDBLStub<br />
$ <br />
<br />
To correct this, set the default compiler to gcc-4.0 (<tt>sudo gcc_select 4.0</tt>) or include linking options <tt>-lHSrts -lSystemStubs</tt> in that order on the ghc command:<br />
<br />
$ ghc --make t2.hs -lHSrts -lSystemStubs<br />
[1 of 1] Skipping Main ( t2.hs, t2.o )<br />
Linking t2 ...<br />
$ <br />
<br />
The command<br />
<br />
for l in <ghc installation directory>/lib/ghc-<ghc version>/*.a; do nm $l 2>&1 | if grep LDBLStub 1>/dev/null; then echo $l; fi; done<br />
<br />
prints the list of libraries that may be needed instead of or in addition to <tt>-lHSrts</tt> before <tt>-lSystemStubs</tt> on the ghc command. For example:<br />
<br />
$ for l in /Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/*.a; do nm $l 2>&1 | if grep LDBLStub 1>/dev/null; then echo $l; fi; done<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSX11_cbits.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts_debug.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts_p.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts_thr.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts_thr_debug.a<br />
/Users/thorkilnaur/tn/install/ghc-HEAD-for-1066-20070211_1657/lib/ghc-6.7.20070209/libHSrts_thr_p.a<br />
$ <br />
<br />
[http://hackage.haskell.org/trac/ghc/ticket/1066] has additional details.<br />
<br />
=== Linking with C++ ===<br />
<br />
==== Linking with a C++ library gives: <tt>Undefined symbols: __Unwind_Resume</tt> ====<br />
<br />
You need to pass the <tt>-fexceptions</tt> to the linker. Use <tt>-optl -fexceptions</tt>.<br />
<br />
---------------------------------------<br />
= Running GHC =<br />
<br />
== Filenames Containing '+' ==<br />
<br />
=== GHC doesn't like filenames containing '+'. ===<br />
<br />
Indeed not. You could change <tt>+</tt> to <tt>p</tt> or <tt>plus</tt>.<br />
<br />
== Linking ==<br />
<br />
=== Why does linking take so long? ===<br />
<br />
Linking a small program should take no more than a few seconds. Larger programs can take longer, but even linking GHC itself only takes 3-4 seconds on our development machines.<br />
<br />
Long link times have been attributed to using Sun's linker on Solaris, as compared to GNU ld which appears to be much faster. So if you're on a Sun box, try switching to GNU ld. [http://www.haskell.org/pipermail/glasgow-haskell-users/2002-November/004477.html This article] from the mailing list has more information.<br />
<br />
One huge slowdown is also working on remote filesystem, e.g., nfs. <br />
Work on a local machine, preferably.<br />
<br />
You may also speed up linking by enabling dynamic linking with the <code>-dynamic</code> option of GHC or <code>--enable-executable-dynamic</code> of [[Cabal]].<br />
<br />
== Missing Include Files ==<br />
<br />
=== Why do I get errors about missing include files when compiling with -O or -prof? ===<br />
<br />
Certain options, such as -O, turn on via-C compilation, instead of using the native code generator. Include files named by -#include options or in foreign import declarations are only used in via-C compilation mode. See [http://www.haskell.org/ghc/docs/latest/html/users_guide/sec-ffi-ghc.html#finding-header-files Section 8.2.2.1, ´Finding Header files] for more details.<br />
<br />
== Compiling for Profiling ==<br />
<br />
=== How do I compile my program for profiling without overwriting the object files and hi files I've already built? ===<br />
<br />
You can select alternative suffixes for object files and interface files, so you can have several builds of the same code coexisting in the same directory. For example, to compile with profiling, you might do this:<br />
<br />
<pre><br />
ghc --make -prof -o foo-prof -osuf p.o -hisuf p.hi Main<br />
</pre><br />
<br />
See [http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#options-output Section 4.6.4, ´Redirecting the compilation output(s)] for more details on the <tt>-osuf</tt> and <tt>-hisuf</tt> options.<br />
<br />
---------------------------------------<br />
= Syntax =<br />
<br />
== String Gaps ==<br />
<br />
=== I can't get string gaps to work ===<br />
<br />
If you're also using CPP, beware of the known pitfall with string gaps mentioned in [http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#cpp-string-gaps Section 4.10.3.1, CPP and string gaps].<br />
<br />
---------------------------------------<br />
= GHCi =<br />
<br />
== Error Messages ==<br />
<br />
=== Missing Symbols ===<br />
<br />
==== GHCi complains about missing symbols like CC_LIST when loading a previously compiled .o file. ====<br />
<br />
This probably means the .o files in question were compiled for profiling (with -prof). Workaround: recompile them without profiling. We really ought to detect this situation and give a proper error message.<br />
<br />
=== Starting GHCi ===<br />
<br />
==== When I try to start ghci (probably one I compiled myself) it says <tt>ghc-5.02: not built for interactive use</tt> ====<br />
To build a working ghci, you need to build GHC 5.02 with itself; the above message appears if you build it with 4.08.X, for example. It'll still work fine for batch-mode compilation, though. Note that you really must build with exactly the same version of the compiler. Building 5.02 with 5.00.2, for example, may or may not give a working interactive system; it probably won't, and certainly isn't supported. Note also that you can build 5.02 with any older compiler, back to 4.08.1, if you don't want a working interactive system; that's OK, and supported.<br />
<br />
=== Duplicate Definitions ===<br />
<br />
==== I get an error message from GHCi about a "<tt>duplicate definition for symbol __module_registered</tt>" ====<br />
<br />
An error message like this:<br />
<br />
<pre><br />
GHCi runtime linker: fatal error: I found a duplicate definition for symbol<br />
__module_registered<br />
whilst processing object file<br />
/usr/local/lib/ghc-6.2/HSfgl.o<br />
</pre><br />
<br />
probably indicates that when building a library for GHCi (<tt>HSfgl.o</tt> in the above example), you should use the <tt>-x</tt> option to <tt>ld</tt>.<br />
<br />
== REPL Workarounds ==<br />
<br />
=== Why doesn't "x=1" work at the ghci prompt? ===<br />
<br />
Type<br />
<pre><br />
let x = 1<br />
</pre><br />
<br />
instead.<br />
<br />
From IRC: "But in general, it's tricky to define function interactively. You can do simple stuff easily enough: "let f x = x * x" or whatever; but for anything other than a simple one-liner, I usually stick it into a file and then load it with ghci.<br />
<br />
---------------------------------------<br />
= The Foreign Function Interface =<br />
<br />
== Blocking ==<br />
<br />
=== When do other Haskell threads get blocked by an FFI call? ===<br />
<br />
{| border="1" align="center"<br />
|<br />
! safe<br />
! unsafe<br />
|-<br />
! -threaded<br />
| NO <br />
| YES<br />
|-<br />
! no -threaded<br />
| YES<br />
| YES<br />
|}<br />
<br />
The <tt>-threaded</tt> flag (given when linking; see the <br />
[http://www.haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html manual])<br />
allows other Haskell threads to run concurrently with a thread making an FFI call.<br />
This nice behaviour does not happen for foreign calls marked as `unsafe` (see<br />
the [http://www.cse.unsw.edu.au/~chak/haskell/ffi/ FFI Addendum]).<br />
<br />
There used to be another modifier, <tt>threadsafe</tt>, which is now deprecated. Use `safe` instead.<br />
<br />
== Using Floats ==<br />
<br />
=== When I use a foreign function that takes or returns a float, it gives the wrong answer, or crashes. ===<br />
<br />
You should use the <tt>-#include</tt> option to bring the correct prototype into scope (see [http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#options-C-compiler Section 4.10.5, ´Options affecting the C compiler (if applicable)]).<br />
<br />
== Propogating Run-time Errors as Exceptions ==<br />
<br />
=== How can I propagate a Haskell run-time error (e.g. pattern match failure) as an exception to a foreign caller of the Haskell function. ===<br />
<br />
If a runtime error occurs inside a DLL compiled by ghc (like <br />
"irrefutable pattern match failed" or exceptions caused by error),<br />
the application that called the DLL function dies. This is ok for <br />
development but unacceptable when it happens with a user sitting in <br />
front of the display. <br />
So the question is: Is there any way to catch and process runtime errors? <br />
I am looking for some way to map those errors to exceptions on the C++ <br />
side that can be caught if required. It would be ok to kill the Haskell <br />
runtime system and unload the DLL if necessary.<br />
<br />
Answer: The FFI doesn't provide any way to propagate exceptions from Haskell to <br />
the caller of a foreign export, because there's no standard way to do <br />
this. It is your responsibility to catch the exception in Haskell and <br />
return an appropriate error code to the caller. To raise a C++ <br />
exception, you would probably need another C++ wrapper around each <br />
foreign export, translating an error code into the C++ exception.<br />
<br />
== Calling C Procedures ==<br />
<br />
=== How do I call a C procedure from a Haskell program? ===<br />
<br />
First, you'll want to keep open <br />
the [http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi.html GHC user manual section on foreign function calling], and the <br />
[http://www.cse.unsw.edu.au/~chak/haskell/ffi/ Haskell FFI addendum].<br />
<br />
Now, let's assume you got this c-program ffi.c which writes THE answer to a file:<br />
<br />
<pre><br />
#include <stdlib.h><br />
#include <stdio.h><br />
<br />
write_answer(char *userfilename)<br />
{<br />
FILE *userfile;<br />
userfile=fopen(userfilename,"w");<br />
fprintf(userfile,"42");<br />
fclose(userfile);<br />
}<br />
</pre><br />
You also need a header file ffi.h.<br />
<pre><br />
void write_answer(char *userfilename)<br />
</pre><br />
Next Step: Write the according Haskell program to include the function<br />
<tt>write_answer</tt> in your Haskell code:<br />
<haskell><br />
{-# INCLUDE <ffi.h> #-}<br />
{-# LANGUAGE ForeignFunctionInterface #-}<br />
module Main where<br />
<br />
import Foreign<br />
import Foreign.C.String <br />
<br />
foreign import ccall "ffi.h write_answer" cwrite_answer :: CString -> IO ()<br />
<br />
write_answer :: String -> IO ()<br />
write_answer s = do<br />
s' <- newCString s<br />
cwrite_answer s'<br />
<br />
main = write_answer "ffi.dat"<br />
</haskell><br />
<br />
Now we get to compiling (assume that <tt>/tmp/ffi/</tt> is the current path).<br />
<pre><br />
cc -fPIC -c ffi.c<br />
ar rc libffi.a ffi.o<br />
ghc -lffi -L/tmp/ffi --make Main<br />
</pre><br />
And the resulting executable should write the file.<br />
<br />
The <tt>-fPIC</tt> parameter to the c compiler is not strictly necessary. <br />
But the result will help us in the next step which is to dynamically link the library for use in GHCi.<br />
<br />
== Compiling C Programs ==<br />
<br />
=== How do I compile my C program to use in GHCi? ===<br />
<br />
Suppose you got your c-program compiled (with <tt>-fPIC</tt> parameter) as described above. If you try to load your file <tt>Main.hs</tt> in GHCi you get an error similar to this:<br />
<pre><br />
Loading object (dynamic) ffi ... failed.<br />
Dynamic linker error message was:<br />
libffi.so: cannot open shared object file: No such file or directory<br />
Whilst trying to load: (dynamic) ffi<br />
</pre><br />
What you need is a shared library. To get it you compile once more:<br />
<pre><br />
cc -shared -o libffi.so ffi.o<br />
</pre><br />
And now it all works fine:<br />
<pre><br />
$ ghci -lffi -L/tmp/ffi Main.hs<br />
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help<br />
Loading package base ... linking ... done.<br />
Loading object (dynamic) ffi ... done<br />
final link ... done<br />
Ok, modules loaded: Main.<br />
Prelude Main> write_answer "test"<br />
Prelude Main> :! cat test<br />
42<br />
Prelude Main> <br />
</pre><br />
<br />
---------------------------------------<br />
<br />
= Input/Output =<br />
<br />
== Strings ==<br />
<br />
=== If I print out a string using <tt>putStr</tt>, and then attempt to read some input using <tt>hGetLine</tt>, I don't see the output from the <tt>putStr</tt>. ===<br />
<br />
The <tt>stdout</tt> handle is line-buffered by default, which means that output sent to the handle is only flushed when a newline (<tt>\n</tt>) is output, the buffer is full, or <tt>hFlush</tt> is called on the <tt>Handle</tt>. The right way to make the text appear without sending a newline is to use <tt>hFlush</tt>:<br />
<br />
<haskell><br />
import System.IO<br />
main = do<br />
putStr "how are you today? "<br />
hFlush stdout<br />
input <- hGetLine stdin<br />
process input<br />
</haskell><br />
<br />
You'll probably find that the behaviour differs when using GHCi: the hFlush isn't necessary to make the text appear. This is because in GHCi we turn off the buffering on stdout, because this is normally what you want in an interpreter: output appears as it is generated.<br />
<br />
=== If I use the above fix, but check for EOF with <tt>isEOF</tt> before prompting for user input, the above problem still happens (GHC 6.12.1) ===<br />
<br />
== Buffering on Handles ==<br />
<br />
=== If I explicitly set the buffering on a Handle to <tt>NoBuffering</tt> I'm not able to enter EOF by typing "Ctrl-D". ===<br />
<br />
This is a consequence of Unixy terminal semantics. Unix does line buffering on terminals in the kernel as part of the terminal processing, unless you turn it off. However, the Ctrl-D processing is also part of the terminal processing which gets turned off when the kernel line buffering is disabled. So GHC tries its best to get NoBuffering semantics by turning off the kernel line buffering, but as a result you lose Ctrl-D. C'est la vie.<br />
<br />
== FIFOs (Named Pipes) ==<br />
<br />
=== When I open a FIFO (named pipe) and try to read from it, I get EOF immediately. ===<br />
<br />
This is a consequence of the fact that GHC opens the FIFO in non-blocking mode. The behaviour varies from OS to OS: on Linux and Solaris you can wait for a writer by doing an explicit threadWaitRead on the file descriptor (gotten from <tt>Posix.handleToFd</tt>) before the first read, but this doesn't work on FreeBSD (although rumour has it that recent versions of FreeBSD changed the behaviour to match other OSs). A workaround for all systems is to open the FIFO for writing yourself, before (or at the same time as) opening it for reading.<br />
<br />
== Importing Functions Returning Char/Short ==<br />
<br />
=== When I foreign import a function that returns char or short, I get garbage back. ===<br />
<br />
This is a known bug in GHC versions prior to 5.02.2. GHC doesn't mask out the more significant bits of the result. It doesn't manifest with gcc 2.95, but apparently shows up with g++ and gcc 3.0.<br />
<br />
---------------------------------------<br />
= Optimization =<br />
<br />
== Garbage Collection ==<br />
<br />
=== My program spent too much time doing garbage collection ===<br />
<br />
Add the "+RTS -A10m" option to the command line when you run your<br />
program. This sets the allocation area size used by the garbage<br />
collector to 10M, which should sufficiently decrease GC times (the<br />
default is 256K; see the section "Running a compiled program" in the<br />
users' guide). You can also add to your program C module containing<br />
statement<br />
<br />
char *ghc_rts_opts = "-A10m";<br />
<br />
to force your program to use this setting on each run.<br />
<br />
== Subexpression Elimination ==<br />
<br />
=== Does GHC do common subexpression elimination? ===<br />
<br />
In general, GHC does not do CSE.<br />
It'd be a relatively easy pass for someone to add, but it can cause space leaks. And it can replace two strictly-evaluated calls with one lazy thunk:<br />
<haskell><br />
let { x = case e of ...; y = case e of ... } in ...<br />
==><br />
let { v = e; x = case v of ...; y = case v of ... } in ...<br />
</haskell><br />
Now <hask>v</hask> is allocated as a thunk. (Of course, that might be well worth it if <hask>e</hask> is an expensive expression.)<br />
<br />
Instead GHC does "opportunistic CSE". If you have <br />
<haskell><br />
let x = e in .... let y = e in ....<br />
</haskell><br />
then it'll discard the duplicate binding. This can still cause space<br />
leaks but it guarantees never to create a new thunk, and it turns out <br />
to be very useful in practice.<br />
<br />
Bottom line: if you care about sharing, do it yourself using <hask>let</hask> <br />
or <hask>where</hask>.<br />
<br />
== Laziness ==<br />
<br />
=== When can I rely on full laziness? ===<br />
<br />
Consider this program<br />
<haskell><br />
f x y = let r = expensive x <br />
in r+y<br />
g vs = map (f 2) vs<br />
</haskell><br />
Since r depends only on x, you might hope that <tt>(expensive 2)</tt> is computed just once. And that is indeed what will happen if you write<br />
<haskell><br />
f_opt x = let r = expensive x <br />
in \y -> r+y<br />
g_opt vs = map (f_opt 2) vs<br />
</haskell><br />
It's easy enough for a compiler to transform f into f_opt. (This is called the "full laziness" transformation.) BUT in the cases when f is fully-applied, f_opt is *less* efficient than f; consider<br />
<haskell><br />
h ys zs = zipWith f_opt ys zs<br />
</haskell><br />
Reason: it's much less efficient to have separate lambdas <tt>\x-> let ... in \y -> e</tt> than one compound lambda <tt>\xy -> e</tt>.<br />
<br />
So the best way to transform f depends on how it is used. When it's used locally and just once, GHC inlines it at the call site and all is good. But when it's exported or called many times, GHC's full laziness transformation uses the following rule: never "float" a let <em>between</em> two lambdas. So it won't transform f into f_opt. <br />
<br />
On the other hand, if you write f_opt, GHC will keep it that way. Furthermore, if a sub-expression can be floated right out of a complete lambda group, GHC will float it out. For example<br />
<haskell><br />
f x vs = map (\y -> y + expensive x) vs<br />
</haskell><br />
Here, the <tt>(expensive x)</tt> can be floated out of the <tt>\x->...</tt> lambda without separating two lambdas, and the full laziness transfom will do just that.<br />
<br />
---------------------------------------<br />
<br />
= Miscellaneous =<br />
<br />
== Upgrading GHC ==<br />
<br />
=== Do I have to recompile all my code if I upgrade GHC? ===<br />
<br />
Yes. There are two reasons for this:<br />
<br />
* GHC does a lot of cross-module optimisation, so compiled code will include parts of the libraries it was compiled against (including the Prelude), so will be deeply tied to the actual version of those libraries it was compiled against. When you upgrade GHC, the libraries may change; even if the external interface of the libraries doesn't change, sometimes internal details may change because GHC optimised the code in the library differently. <br />
* We sometimes change the ABI (application binary interface) between versions of GHC. Code compiled with one version of GHC is not necessarily compatible with code compiled by a different version, even if you arrange to keep the same libraries.<br />
<br />
== Shared Libraries ==<br />
<br />
=== Why doesn't GHC use shared libraries? ===<br />
<br />
GHC does provide shared libraries, currently only on MacOS X. We are working on making shared libraries work on other platforms.<br />
<br />
However, GHC-compiled libraries are very tightly coupled, which means it's unlikely you'd be able to swap out a shared library for a newer version unless it was compiled with exactly the same compiler and set of libraries as the old version.<br />
<br />
== Debugging ==<br />
<br />
=== My program is failing with head [], or an array bounds error, or some other random error, and I have no idea how to find the bug. Can you help? ===<br />
<br />
Try the [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html GHCi Debugger], in particular look at the section on "Debugging Exceptions".<br />
<br />
Alternatively, compile your program with <tt>-prof -auto-all</tt> (make sure you have the profiling libraries installed), and run it with <tt>+RTS -xc -RTS</tt> to get a ´stack trace at the point at which the exception was raised. See [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-options-debugging Section 4.14.4, ´RTS options for hackers, debuggers, and over-interested souls] for more details.<br />
<br />
== Increasing Heap Size ==<br />
<br />
=== How do I increase the heap size permanently for a given binary? ===<br />
<br />
See [http://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html#rts-hooks Section 4.14.5, ´´Hooks to change RTS behaviour].<br />
<br />
== Compiling for Parallel Execution ==<br />
<br />
=== I'm trying to compile my program for parallel execution with the -parallel, and GHC complains with an error like 'failed to load interface file for Prelude'. ===<br />
<br />
GHC doesn't ship with support for parallel execution; that support is provided separately by the [http://www.macs.hw.ac.uk/~dsg/gph/ GPH] project.<br />
<br />
== Using Unsafe Functions ==<br />
<br />
=== When is it safe to use [[unsafe functions]] such as <hask>unsafePerformIO</hask>? ===<br />
<br />
We'll give two answers to this question, each of which may be helpful. These criteria are not rigorous in any real sense (you'd need a formal semantics for Haskell in order to give a proper answer to this question), but should give you a feel for the kind of things you can and cannot do with unsafePerformIO.<br />
<br />
* It is safe to implement a function or API using unsafePerformIO if you could imagine also implementing the same function or API in Haskell without using unsafePerformIO (forget about efficiency, just consider the semantics).<br />
* In pure Haskell, the value of a function depends only on the values of its arguments (and free variables, if it has any). If you can implement the function using unsafePerformIO and still retain this invariant, then you're probably using unsafePerformIO in a safe way. Note that you need only consider the observable values of the arguments and result.<br />
<br />
For more information, see [http://www.haskell.org/pipermail/glasgow-haskell-users/2002-July/003681.html this thread].<br />
<br />
== Using Finalizers ==<br />
<br />
=== I can't get finalizers to work properly. My program sometimes just prints <tt><<loop>></tt>. ===<br />
<br />
Chances are that your program is trying to write a message to stdout or stderr in the finalizer. Handles have finalizers themselves, and since finalizers don't keep other finalized values alive, the stdout and stderr Handles may be finalized before your finalizer runs. If this happens, your finalizer will block on the handle, and probably end up receiving a NonTermination exception (which is printed as <tt><<loop>></tt>).<br />
<br />
== Extensible Records ==<br />
<br />
=== Does GHC implement any kind of extensible records? ===<br />
<br />
No, extensible records are not implemented in GHC. [http://www.haskell.org/hugs/ Hugs] implements TRex, one extensible record variant. The problem is that the record design space is large, and seems to lack local optima. And all reasonable variants break backward compatibility. As a result, nothing much happens.<br />
<br />
== Using Extra GCC/Linker Options ==<br />
<br />
=== How can I make GHC always use some extra gcc or linker option? ===<br />
<br />
If you want to *always* use an extra option then you can edit the package configuration for the 'rts' or 'base' package since these packages are used by every program that you compile with GHC. You might want to do this if you had installed something that ghc needs but into a non-standard directory, thus requiring special compilation or linking options.<br />
<br />
All you need to do is to dump out the configuration into a human readable form, edit it and re-register the modified package configuration. The exact commands to do that are below, but first here are the fields in the file that you might want to modify:<br />
<br />
; include-dirs: directories to search for .h files<br />
; library-dirs: directories to search for libraries<br />
; extra-libraries: extra C libs to link with<br />
; cc-options: extra flags to pass to gcc when compiling C code or assembly<br />
; ld-options: extra flags to pass to '''gcc''' when linking<br />
<br />
to edit the rts package (or base) confiuration just do:<br />
# <tt>ghc-pkg describe rts > rts.package.conf</tt><br />
# edit <tt>rts.package.conf</tt> with your favourite text editor<br />
# <tt>ghc-pkg update rts.package.conf</tt><br />
<br />
On Unix systems and Windows, some options can also be set with environment variables such as LIBRARY_PATH and C_INCLUDE_PATH.</div>Lemminghttps://wiki.haskell.org/index.php?title=Terminator_vs._separator&diff=57551Terminator vs. separator2014-02-09T11:11:55Z<p>Lemming: /* Terminators are better */ out-commenting</p>
<hr />
<div>There are several concepts for notation of sequences of elements.<br />
Usually, we don't think much about it.<br />
Programming languages provide different schemes,<br />
often different schemes in the same language,<br />
we are used to them, and no scheme seems to be better than the other one.<br />
However, there are differences and good reasons for preferences.<br />
<br />
== Terms ==<br />
<br />
* Separator: There is a symbol between each element. This is what the functions <hask>Data.List.intersperse</hask> and <hask>Data.List.unwords</hask> generate. In Haskell language, the following syntaxes allow separators only:<br />
** list [[syntactic sugar|sugar]]: <hask>[0,1,2,3]</hask><br />
** tuples: <hask>(0,1,2,3)</hask><br />
** type class constraints: <hask>f :: (Show a, Ord a) => a -> a</hask><br />
** declaration of named record fields: <hask>data T = Cons {a :: Int, b :: String}</hask><br />
** declaration of data constructors: <hask>data T = A | B | C</hask><br />
* Terminator: There is one symbol after each element.<br />
** [[list notation]] using infixes can be considered an example: <hask>0:1:2:3:[]</hask><br />
* Liberal choice between separators and terminators:<br />
** export lists: <hask>module A(a,b,c) where</hask> and <hask>module A(a,b,c,) where</hask> (and <hask>module A(a,b,c,,,) where</hask> ...)<br />
** import lists: <hask>import A(a,b,c)</hask> and <hask>import A(a,b,c,)</hask><br />
** let syntax: <hask>let a = 'a'; b = 'b' in ...</hask> and <hask>let a = 'a'; b = 'b'; in ...</hask><br />
** do syntax: <hask>do a ; b</hask> and <hask>do a; b;</hask><br />
* Initiator? Theoretically it would also be possible to introduce each list element with some symbol. However, I don't know if this is used somewhere.<br />
<br />
== Terminators are better ==<br />
<br />
* The theoretical reason: In separator notations there is one comma less than the number of elements. An empty list would need -1 commas, which can't be written, obviously. That is, empty lists must always be handled differently in the separator approach. There is no such problem with terminators.<br />
* The practical reason: In terminator notation, each list element is followed by the terminator symbol. Thus it is easier to reorder the elements of a list in an editor. If you have written <hask>(1:2:3:[])</hask> you can simply cut some elements and the subsequent ':' and then you can insert them whereever you want. If you place every element at a line then it is easy to disable individual lines with a line comment (starting with <hask>--</hask>). This formatting is also optimal for line oriented [[Darcs|version control systems]] and diff.<br />
<br />
== See also ==<br />
<br />
* [[List notation]]<br />
<br />
[[Category:Syntax]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Common_Misunderstandings&diff=57523Common Misunderstandings2014-01-30T20:27:16Z<p>Lemming: /* See also */ move heading one level up</p>
<hr />
<div>[[Category:FAQ]]<br />
<br />
= Common Mistakes and Incorrect Beliefs By Haskell Beginners=<br />
People going from zero to Haskell are likely to gain a misunderstanding or miss a point that isn't stressed enough. Here are some mistakes that have been observed from multiple sources.<br />
<br />
== Indentation ==<br />
Perhaps the first trip-up - you might understand that indentation defines where a code block starts and the lack of an equal amount of indentation indicates the previous code block ended. What some miss is that <hask>then</hask> and <hask>else</hask> must be indented deeper than the <hask>if</hask> statement:<br />
<br />
<haskell><br />
if boolean<br />
then expr1<br />
else expr2<br />
</haskell><br />
<br />
Or they can be on the same line as the if:<br />
<br />
<haskell><br />
if boolean then expr1 else expr2<br />
</haskell><br />
<br />
== If / Then / Else ==<br />
if-then statements must always include an 'else' portion. It might be best not to think of if-then-else as flow control, as in most imperative languages, but think of it as construction of a value using a well formed expression.<br />
<br />
<code><br />
x = b ? y : z;<br />
</code><br />
<br />
The above is valid C code, a [http://en.wikipedia.org/wiki/Ternary_operation ternary operation], that's used quite commonly as a shortcut to typing out a full if-then-else block. It states that if <code>b</code> is true then <code>x = y</code> otherwise <code>x = z</code>. Notice how this makes no sense without <code>z</code>. Similarly, in Haskell an <hask>if</hask>/<hask>then</hask> makes no sense without an <hask>else</hask>.<br />
<br />
<haskell><br />
let x = if b then y -- compare to x = b ? y<br />
</haskell><br />
<br />
What is <code>x</code> when <code>b</code> is false? One should also recognize that the types returned by the <hask>then</hask> and <hask>else</hask> branches must match due to Haskells strong and static type system.<br />
<br />
When <hask>if</hask> is used for sequencing IO it is not uncommon to see an <hask>else</hask> that returns a null value:<br />
<br />
<haskell><br />
main = do<br />
startNetwork <- askUser "Network? "<br />
if startNetwork<br />
then do iface <- initNetworkInterface<br />
handlePackets iface<br />
else return ()<br />
</haskell><br />
<br />
Such uses can be more succinct if they use the <hask>when</hask> function (from the Control.Monad module):<br />
<br />
<haskell><br />
main = do<br />
startNetwork <- askUser "Network? "<br />
when startNetwork $ do<br />
iface <- initNetworkInterface<br />
handlePackets iface<br />
</haskell><br />
<br />
== Binding of Type Signatures ==<br />
Due to the typeclass overloading of numbers, lists of numbers are often typed as:<br />
<br />
<haskell><br />
ghci> [1,2,3,4] :: [Float]<br />
</haskell><br />
<br />
This works fine when the list stands alone, but when applying a function take note the function application binds stronger than the type signature. This means the below signature is invalid:<br />
<br />
<haskell><br />
ghci> map floor [1,2,3,4] :: [Float]<br />
</haskell><br />
<br />
and should instead be:<br />
<haskell><br />
ghci> map floor ([1,2,3,4] :: [Float])<br />
</haskell><br />
<br />
== '''do''' Notation ==<br />
If the [[do notation]] page ever exists I'll advise you to check it out. Until then, understand that a missing <hask>do</hask> from the top of a function or code block can result in your compiler giving an error message citing a much later line number. Also, any new blocks (ex: from an <hask>if</hask> or <hask>case</hask>) must have their own <hask>do</hask>, even if the higher level code block already had one.<br />
<br />
Sorry this isn't the full picture - for an inverse point of view see [[do notation considered harmful]].<br />
<br />
== Iterating Over a List ==<br />
Some beginners make the mistake of mistaking a single-element list pattern (such as <hask>[x]</hask>) for a pattern that iterates over every element in the list.<br />
<br />
One example that recently (in April, 2008) appeared on the Haskell-Cafe mailing list (see the reply post [http://www.haskell.org/pipermail/haskell-cafe/2008-April/041701.html Re: Embedding newlines into a string?]) was the following. Here, one coder attempted to write a function <hask>hanoi</hask> to solve the Towers of Hanoi problem, but to code it so that each tower could be named polymorphically, using, for example, either Chars or Ints. The problematic code segment was the following:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [(a, b)] = "Move " ++ show a ++ " to " ++ show b ++ "."<br />
</haskell><br />
<br />
in the following program:<br />
<br />
<haskell><br />
hanoi :: a -> a -> a -> Int -> [(a, a)]<br />
hanoi source using dest n<br />
| n == 1 = [(source, dest)]<br />
| otherwise = hanoi source dest using (n-1)<br />
++ hanoi source using dest 1<br />
++ hanoi using source dest (n-1)<br />
<br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [(a, b)] = "Move " ++ show a ++ " to " ++ show b ++ "."<br />
</haskell><br />
<br />
The coder tried to run the code in WinHugs as follows:<br />
<br />
<hask><br />
Main> putStr (hanoi_shower (hanoi 'a' 'b' 'c' 2))<br />
</hask><br />
<br />
However, this was the result:<br />
<br />
<hask><br />
Program error: pattern match failure: hanoi_shower<br />
[('a','b'),('a','c')] ++ ([] ++ hanoi 'b' 'a' 'c' (2 - 1))<br />
</hask><br />
<br />
The problem was that the parameter <hask>[(a, b)]</hask> to <hask>hanoi_shower</hask> only matched the first element of the list, but didn't iterate over the list as intended.<br />
<br />
Here is a corrected version of the code above:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower moves = unlines ["Move " ++ show a ++ " to "++ show b ++ "." | (a, b) <- moves]<br />
</haskell><br />
<br />
Here, <hask>moves</hask> is pattern-matched to type <hask>[(a, a)]</hask> (a list of pairs). The problem is how to iterate over the elements (pairs) of the list while separating the first <hask>a</hask> of each pair from the second <hask>a</hask>.<br />
<br />
The solution above uses list comprehension: The generator <hask>(a, b) <- moves</hask> feeds each pair in turn to the left-hand expression <hask>(a, b)</hask>, and this pair is mapped to the left expression, <hask>"Move " ++ show a ++ " to "++ show b ++ "."</hask>, building a new list of sentences representing moves. Then, the function <hask>unlines</hask> breaks this list into a sequence of lines.<br />
<br />
Here is the result of executing the above code in WinHugs:<br />
<br />
<hask><br />
Main> putStr (hanoi_shower (hanoi 'a' 'b' 'c' 2))<br />
Move 'a' to 'b'.<br />
Move 'a' to 'c'.<br />
Move 'b' to 'c'.<br />
<br />
Main> putStr (hanoi_shower (hanoi 1 2 3 2))<br />
Move 1 to 2.<br />
Move 1 to 3.<br />
Move 2 to 3.<br />
</hask><br />
<br />
Notice that since <hask>a</hask> and <hask>b</hask> in <hask>(a, b)</hask> are polymorphic types, they can range over both <hask>Chars</hask> and <hask>Ints</hask>.<br />
<br />
Another way of writing <hask>hanoi_shower</hask>, using <hask>map</hask>, is as follows:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower moves = unlines (map move moves)<br />
where move (a, b) = "Move " ++ show a ++ " to "++ show b ++ "."<br />
</haskell><br />
<br />
Here, <hask>move</hask> is mapped over <hask>moves</hask>, and each pair <hask>(a, b)</hask> of <hask>moves</hask> is pattern-matched against <hask>"Move " ++ show a ++ " to "++ show b ++ "."</hask><br />
<br />
Another way to map over a list is to use recursion, although this method is considered non-idiomatic Haskell (Haskellers generally prefer using higher-order functions over recursion when possible):<br />
<br />
<haskell><br />
hanoi :: a -> a -> a -> Int -> [(a, a)]<br />
hanoi source using dest n<br />
| n == 0 = []<br />
| n == 1 = [(source, dest)]<br />
| otherwise = hanoi source dest using (n-1) <br />
++ hanoi source using dest 1<br />
++ hanoi using source dest (n-1)<br />
<br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [] = ""<br />
hanoi_shower ((a, b):moves) = unlines ["Move " ++ show a ++ " to "++ show b ++ "."] ++ hanoi_shower moves<br />
</haskell><br />
<br />
Here, in <hask>hanoi_shower</hask>, the base case is simply an empty list <hask>[]</hask>. At each recursive step, a list of type <hask>[(a, a)]</hask> (a list of pairs) is mapped against the parameter <hask>(a, b):moves</hask> of <hask>hanoi_shower</hask>. This separates the head of the list <hask>(a, b)</hask> from the tail of the list <hask>moves</hask>, which then is further matched against <hask>((a, b):moves)</hask> on the next recursive call.<br />
<br />
There are other ways of iterating over lists as well. One advantage of Haskell is that there are often many ways of performing the same action, including iterating over lists.<br />
<br />
== Guards ==<br />
(The following two tips on guards were contributed by the user 7stud in the thread "Top beginner mistakes" (see http://article.gmane.org/gmane.comp.lang.haskell.beginners/1121) on the Haskell-Beginners mailing list on Wed, 4 Mar 2009 21:54:05 +0000 (UTC).)<br />
<br />
Some beginners make the mistake of putting an equals sign after a function name when using guards; ''viz.'':<br />
<br />
<haskell><br />
myfunction x y =<br />
| x < 2 = "a"<br />
| y > 20 = "b"<br />
| otherwise = "c"<br />
</haskell><br />
<br />
This causes a cryptic error message similar to the following to be displayed:<br />
<br />
<hask><br />
dhask.hs:2:4: parse error on input `|'<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
Another common mistake that some beginners make is writing "if" in front of the guard conditions; ''viz.'':<br />
<br />
<haskell><br />
myfunction x y<br />
| if x < 2 = "a"<br />
| if y > 20 = "b"<br />
| otherwise = "c"<br />
</haskell><br />
<br />
This causes a mysterious error message similar to the following to be shown:<br />
<br />
<hask><br />
dhask.hs:2:25: parse error on input `='<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
In both cases, the error messages don't help to identify the problem.<br />
<br />
(Entry added by [[User:DekuDekuplex|Benjamin L. Russell]].)<br />
<br />
== Parentheses ==<br />
(The following tip on parentheses was contributed by the user 7stud in the thread "Top beginner mistakes" (see http://article.gmane.org/gmane.comp.lang.haskell.beginners/1121) on the Haskell-Beginners mailing list on Wed, 4 Mar 2009 21:54:05 +0000 (UTC).)<br />
<br />
Some beginners make the mistake of not putting parentheses around arguments of the form x:xs; ''viz.'':<br />
<br />
<haskell><br />
dosomething x:xs = head xs<br />
</haskell><br />
<br />
This causes an ambiguous error message similar to the following to be shown:<br />
<br />
<hask><br />
dhask.hs:1:0: Parse error in pattern<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
Here, the error message doesn't help to recognize the problem.<br />
<br />
(Entry added by [[User:DekuDekuplex|Benjamin L. Russell]].)<br />
<br />
<br />
= See also =<br />
<br />
* [[What a Monad is not]]</div>Lemminghttps://wiki.haskell.org/index.php?title=Common_Misunderstandings&diff=57522Common Misunderstandings2014-01-30T20:26:48Z<p>Lemming: See also: What a monad is not</p>
<hr />
<div>[[Category:FAQ]]<br />
<br />
= Common Mistakes and Incorrect Beliefs By Haskell Beginners=<br />
People going from zero to Haskell are likely to gain a misunderstanding or miss a point that isn't stressed enough. Here are some mistakes that have been observed from multiple sources.<br />
<br />
== Indentation ==<br />
Perhaps the first trip-up - you might understand that indentation defines where a code block starts and the lack of an equal amount of indentation indicates the previous code block ended. What some miss is that <hask>then</hask> and <hask>else</hask> must be indented deeper than the <hask>if</hask> statement:<br />
<br />
<haskell><br />
if boolean<br />
then expr1<br />
else expr2<br />
</haskell><br />
<br />
Or they can be on the same line as the if:<br />
<br />
<haskell><br />
if boolean then expr1 else expr2<br />
</haskell><br />
<br />
== If / Then / Else ==<br />
if-then statements must always include an 'else' portion. It might be best not to think of if-then-else as flow control, as in most imperative languages, but think of it as construction of a value using a well formed expression.<br />
<br />
<code><br />
x = b ? y : z;<br />
</code><br />
<br />
The above is valid C code, a [http://en.wikipedia.org/wiki/Ternary_operation ternary operation], that's used quite commonly as a shortcut to typing out a full if-then-else block. It states that if <code>b</code> is true then <code>x = y</code> otherwise <code>x = z</code>. Notice how this makes no sense without <code>z</code>. Similarly, in Haskell an <hask>if</hask>/<hask>then</hask> makes no sense without an <hask>else</hask>.<br />
<br />
<haskell><br />
let x = if b then y -- compare to x = b ? y<br />
</haskell><br />
<br />
What is <code>x</code> when <code>b</code> is false? One should also recognize that the types returned by the <hask>then</hask> and <hask>else</hask> branches must match due to Haskells strong and static type system.<br />
<br />
When <hask>if</hask> is used for sequencing IO it is not uncommon to see an <hask>else</hask> that returns a null value:<br />
<br />
<haskell><br />
main = do<br />
startNetwork <- askUser "Network? "<br />
if startNetwork<br />
then do iface <- initNetworkInterface<br />
handlePackets iface<br />
else return ()<br />
</haskell><br />
<br />
Such uses can be more succinct if they use the <hask>when</hask> function (from the Control.Monad module):<br />
<br />
<haskell><br />
main = do<br />
startNetwork <- askUser "Network? "<br />
when startNetwork $ do<br />
iface <- initNetworkInterface<br />
handlePackets iface<br />
</haskell><br />
<br />
== Binding of Type Signatures ==<br />
Due to the typeclass overloading of numbers, lists of numbers are often typed as:<br />
<br />
<haskell><br />
ghci> [1,2,3,4] :: [Float]<br />
</haskell><br />
<br />
This works fine when the list stands alone, but when applying a function take note the function application binds stronger than the type signature. This means the below signature is invalid:<br />
<br />
<haskell><br />
ghci> map floor [1,2,3,4] :: [Float]<br />
</haskell><br />
<br />
and should instead be:<br />
<haskell><br />
ghci> map floor ([1,2,3,4] :: [Float])<br />
</haskell><br />
<br />
== '''do''' Notation ==<br />
If the [[do notation]] page ever exists I'll advise you to check it out. Until then, understand that a missing <hask>do</hask> from the top of a function or code block can result in your compiler giving an error message citing a much later line number. Also, any new blocks (ex: from an <hask>if</hask> or <hask>case</hask>) must have their own <hask>do</hask>, even if the higher level code block already had one.<br />
<br />
Sorry this isn't the full picture - for an inverse point of view see [[do notation considered harmful]].<br />
<br />
== Iterating Over a List ==<br />
Some beginners make the mistake of mistaking a single-element list pattern (such as <hask>[x]</hask>) for a pattern that iterates over every element in the list.<br />
<br />
One example that recently (in April, 2008) appeared on the Haskell-Cafe mailing list (see the reply post [http://www.haskell.org/pipermail/haskell-cafe/2008-April/041701.html Re: Embedding newlines into a string?]) was the following. Here, one coder attempted to write a function <hask>hanoi</hask> to solve the Towers of Hanoi problem, but to code it so that each tower could be named polymorphically, using, for example, either Chars or Ints. The problematic code segment was the following:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [(a, b)] = "Move " ++ show a ++ " to " ++ show b ++ "."<br />
</haskell><br />
<br />
in the following program:<br />
<br />
<haskell><br />
hanoi :: a -> a -> a -> Int -> [(a, a)]<br />
hanoi source using dest n<br />
| n == 1 = [(source, dest)]<br />
| otherwise = hanoi source dest using (n-1)<br />
++ hanoi source using dest 1<br />
++ hanoi using source dest (n-1)<br />
<br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [(a, b)] = "Move " ++ show a ++ " to " ++ show b ++ "."<br />
</haskell><br />
<br />
The coder tried to run the code in WinHugs as follows:<br />
<br />
<hask><br />
Main> putStr (hanoi_shower (hanoi 'a' 'b' 'c' 2))<br />
</hask><br />
<br />
However, this was the result:<br />
<br />
<hask><br />
Program error: pattern match failure: hanoi_shower<br />
[('a','b'),('a','c')] ++ ([] ++ hanoi 'b' 'a' 'c' (2 - 1))<br />
</hask><br />
<br />
The problem was that the parameter <hask>[(a, b)]</hask> to <hask>hanoi_shower</hask> only matched the first element of the list, but didn't iterate over the list as intended.<br />
<br />
Here is a corrected version of the code above:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower moves = unlines ["Move " ++ show a ++ " to "++ show b ++ "." | (a, b) <- moves]<br />
</haskell><br />
<br />
Here, <hask>moves</hask> is pattern-matched to type <hask>[(a, a)]</hask> (a list of pairs). The problem is how to iterate over the elements (pairs) of the list while separating the first <hask>a</hask> of each pair from the second <hask>a</hask>.<br />
<br />
The solution above uses list comprehension: The generator <hask>(a, b) <- moves</hask> feeds each pair in turn to the left-hand expression <hask>(a, b)</hask>, and this pair is mapped to the left expression, <hask>"Move " ++ show a ++ " to "++ show b ++ "."</hask>, building a new list of sentences representing moves. Then, the function <hask>unlines</hask> breaks this list into a sequence of lines.<br />
<br />
Here is the result of executing the above code in WinHugs:<br />
<br />
<hask><br />
Main> putStr (hanoi_shower (hanoi 'a' 'b' 'c' 2))<br />
Move 'a' to 'b'.<br />
Move 'a' to 'c'.<br />
Move 'b' to 'c'.<br />
<br />
Main> putStr (hanoi_shower (hanoi 1 2 3 2))<br />
Move 1 to 2.<br />
Move 1 to 3.<br />
Move 2 to 3.<br />
</hask><br />
<br />
Notice that since <hask>a</hask> and <hask>b</hask> in <hask>(a, b)</hask> are polymorphic types, they can range over both <hask>Chars</hask> and <hask>Ints</hask>.<br />
<br />
Another way of writing <hask>hanoi_shower</hask>, using <hask>map</hask>, is as follows:<br />
<br />
<haskell><br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower moves = unlines (map move moves)<br />
where move (a, b) = "Move " ++ show a ++ " to "++ show b ++ "."<br />
</haskell><br />
<br />
Here, <hask>move</hask> is mapped over <hask>moves</hask>, and each pair <hask>(a, b)</hask> of <hask>moves</hask> is pattern-matched against <hask>"Move " ++ show a ++ " to "++ show b ++ "."</hask><br />
<br />
Another way to map over a list is to use recursion, although this method is considered non-idiomatic Haskell (Haskellers generally prefer using higher-order functions over recursion when possible):<br />
<br />
<haskell><br />
hanoi :: a -> a -> a -> Int -> [(a, a)]<br />
hanoi source using dest n<br />
| n == 0 = []<br />
| n == 1 = [(source, dest)]<br />
| otherwise = hanoi source dest using (n-1) <br />
++ hanoi source using dest 1<br />
++ hanoi using source dest (n-1)<br />
<br />
hanoi_shower :: Show a => [(a, a)] -> String<br />
hanoi_shower [] = ""<br />
hanoi_shower ((a, b):moves) = unlines ["Move " ++ show a ++ " to "++ show b ++ "."] ++ hanoi_shower moves<br />
</haskell><br />
<br />
Here, in <hask>hanoi_shower</hask>, the base case is simply an empty list <hask>[]</hask>. At each recursive step, a list of type <hask>[(a, a)]</hask> (a list of pairs) is mapped against the parameter <hask>(a, b):moves</hask> of <hask>hanoi_shower</hask>. This separates the head of the list <hask>(a, b)</hask> from the tail of the list <hask>moves</hask>, which then is further matched against <hask>((a, b):moves)</hask> on the next recursive call.<br />
<br />
There are other ways of iterating over lists as well. One advantage of Haskell is that there are often many ways of performing the same action, including iterating over lists.<br />
<br />
== Guards ==<br />
(The following two tips on guards were contributed by the user 7stud in the thread "Top beginner mistakes" (see http://article.gmane.org/gmane.comp.lang.haskell.beginners/1121) on the Haskell-Beginners mailing list on Wed, 4 Mar 2009 21:54:05 +0000 (UTC).)<br />
<br />
Some beginners make the mistake of putting an equals sign after a function name when using guards; ''viz.'':<br />
<br />
<haskell><br />
myfunction x y =<br />
| x < 2 = "a"<br />
| y > 20 = "b"<br />
| otherwise = "c"<br />
</haskell><br />
<br />
This causes a cryptic error message similar to the following to be displayed:<br />
<br />
<hask><br />
dhask.hs:2:4: parse error on input `|'<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
Another common mistake that some beginners make is writing "if" in front of the guard conditions; ''viz.'':<br />
<br />
<haskell><br />
myfunction x y<br />
| if x < 2 = "a"<br />
| if y > 20 = "b"<br />
| otherwise = "c"<br />
</haskell><br />
<br />
This causes a mysterious error message similar to the following to be shown:<br />
<br />
<hask><br />
dhask.hs:2:25: parse error on input `='<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
In both cases, the error messages don't help to identify the problem.<br />
<br />
(Entry added by [[User:DekuDekuplex|Benjamin L. Russell]].)<br />
<br />
== Parentheses ==<br />
(The following tip on parentheses was contributed by the user 7stud in the thread "Top beginner mistakes" (see http://article.gmane.org/gmane.comp.lang.haskell.beginners/1121) on the Haskell-Beginners mailing list on Wed, 4 Mar 2009 21:54:05 +0000 (UTC).)<br />
<br />
Some beginners make the mistake of not putting parentheses around arguments of the form x:xs; ''viz.'':<br />
<br />
<haskell><br />
dosomething x:xs = head xs<br />
</haskell><br />
<br />
This causes an ambiguous error message similar to the following to be shown:<br />
<br />
<hask><br />
dhask.hs:1:0: Parse error in pattern<br />
Failed, modules loaded: none.<br />
</hask><br />
<br />
Here, the error message doesn't help to recognize the problem.<br />
<br />
(Entry added by [[User:DekuDekuplex|Benjamin L. Russell]].)<br />
<br />
<br />
== See also ==<br />
<br />
* [[What a Monad is not]]</div>Lemminghttps://wiki.haskell.org/index.php?title=What_a_Monad_is_not&diff=57521What a Monad is not2014-01-30T20:24:39Z<p>Lemming: Category:Monad</p>
<hr />
<div>==Warning==<br />
Don't be surprised if you leave this page more confused than before. That just means that it has successfully destroyed your false assumptions, or that you've fallen for some horrible inside joke. Beware of [[Zygohistomorphic prepromorphisms]]. Go for [http://ertes.de/articles/monads.html warm and fuzzy], instead.<br />
<br />
==Monads are not a good choice as topic for your first Haskell blog entry==<br />
...just accept that they're [http://blog.plover.com/prog/burritos.html burritos], and wait until later.<br />
<br />
==Monads are not a language feature==<br />
Really. They are defined in terms of Haskell, not Haskell in terms of them. Conversely,<br />
<br />
==Haskell doesn't need Monads==<br />
...well, apart from the current Haskell standard defining the way IO is done in terms of Monads: [http://donsbot.wordpress.com/2009/01/31/reviving-the-gofer-standard-prelude-circa-1994/ It could be done differently and still work].<br />
<br />
==Monads are not impure==<br />
...In no way whatsoever. You don't even need flexible morals to claim it. To be more specific, it's IO that's impure. That makes the IO monad impure. But that's not a general property of monads - just IO. And even then, we can pretend that Haskell is a purely functional description language for imperative programs. But we didn't want to employ flexible morals, now did we?<br />
<br />
==Monads are not about state==<br />
While it is certainly possible to abstract away explicit state passing by using a Monad, that's not what a monad is. Some examples for monads that are not about state: Identity monad, Reader monad, List monad, Continuation monad, Exception monad.<br />
<br />
==Monads are not about strictness==<br />
Monad operations (bind and return) have to be [[Non-strict semantics|non-strict]] in fact, always! However<br />
other operations can be specific to each monad.<br />
For instance some are strict (like IO), and some are non-strict (like []). Then there are some that come in multiple flavours, like State.<br />
<br />
Try the following:<br />
<br />
<haskell><br />
runState (sequence . repeat $ state (\x -> (x,x+1))) 0<br />
</haskell><br />
<br />
Having a look at the implementation of fixIO might be helpful, too.<br />
<br />
==Monads are not values==<br />
This point might be driven home best by pointing out that instance Monad Foo where ... is not a data type, but a declaration of a typeclass instance. However, to elaborate:<br />
<br />
Monads are not values in the same sense that addition and multiplication are not numbers: They capture a -- very specific -- relationship between values of a specific domain into a common abstraction. We're going to call these values monads manage ''mobits'', somewhat like this:<br />
<br />
<haskell><br />
type Mobit m a = Monad m => m a<br />
</haskell><br />
<br />
The IO monad manages mobits representing side-effects ("IO actions").<br />
<br />
The List monad manages mobits representing multiple values ("[a]")<br />
<br />
The Reader monads manages mobits that are pure computations that use asks to propagate information instead of explicit arguments<br />
<br />
...and while addition and multiplication are both monoids over the positive natural numbers, a monad is a monoid object in a category of endofunctors: return is the unit, and join is the binary operation. It couldn't be more simple. If that confuses you, it might be helpful to see a Monad as a lax functor from a terminal bicategory.<br />
<br />
==Monads are not a replacement for applicative functors==<br />
Instead, every monad ''is'' an applicative functor (as well as a functor). It is considered good practice not to use >>= if all you need is <*>, or even fmap.<br />
<br />
Not confusing which features of monads are specific to monads only and which stem from applicative functors is vitally important for a deeper understanding of monads. As an example, the applicative functor interface of parser libraries can parse context-free languages (modulo hacks abusing open recursion), while the monadic interface can parse context-sensitive grammars: Monads allow you to influence further processing by inspecting the result of your parse. To understand why, have a look at the type of >>=. To understand why applicative functors by themselves are sufficient to track the current parsing position and express sequencing, have a look at the [http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-044.pdf uu-parsinglib tutorial (pdf)].<br />
<br />
The exact differences are elaborated in even greater detail in Brent Yorgey's excellent [[Typeclassopedia]].<br />
<br />
==Monads are not about ordering/sequencing==<br />
Monads are commonly used to order sequences of computations. But this is misleading. Just as you can use monads for state, or strictness, you can use them to order computations. But there are also commutative monads, like Maybe, that don't order anything. So ordering is not in any way essential to what a monad is.<br />
<br />
Let's have a look at what's meant by ordering. Consider an expression like<br />
<br />
<haskell><br />
let x = a<br />
y = b<br />
in f x y<br />
</haskell><br />
<br />
That gives the same result as<br />
<br />
<haskell><br />
let y = b<br />
x = a<br />
in f x y<br />
</haskell><br />
<br />
It doesn't matter what order we write the two bindings. But for doing I/O we'd like ordering. Monads allow us to express<br />
<br />
<haskell><br />
do<br />
x <- getChar<br />
y <- getChar<br />
return (x,y)<br />
</haskell><br />
<br />
and have it be different from<br />
<br />
<haskell><br />
do<br />
y <- getChar<br />
x <- getChar<br />
return (x,y)<br />
</haskell><br />
<br />
Unlike the first, the second example returns a pair of characters in the opposite order to which they were entered.<br />
<br />
It might help to meditate about the difference between 'assignment' and 'binding', right now.<br />
<br />
However, just to spoil the enlightenment you just attained, there are monads for which swapping the order of lines like this makes no difference: For example, the Maybe monad.<br />
<br />
So while it is correct to say that monads can be used to order operations, it would be wrong to say that monads are a mechanism for ordering operations.<br />
<br />
This notion of commutativity looks superficially very different from the familiar one in vanilla algebra where a+b=b+a. It's not about the fact that<br />
<br />
<haskell><br />
(Just 2 >> Just 3) == Just 3<br />
</haskell><br />
, implying <br />
<haskell><br />
(Just 2 >> Just 3) /= (Just 3 >> Just 2)<br />
</haskell><br />
<br />
This shouldn't be too surprising, though, as >> isn't the binary operation of some monoid: the algebraic properties of '''''join''''' are very close to those of + and incidentally, '''''join''''' is also the operation true category theorists tend to work with. They also know of bind, but don't use it a lot because, unlike programmers, they don't do any actual productive work.<br />
<br />
==See also==<br />
<br />
* [[Do notation considered harmful]]<br />
<br />
[[Category:FAQ]]<br />
[[Category:Monad]]</div>Lemming