Affichage des articles dont le libellé est haskell. Afficher tous les articles
Affichage des articles dont le libellé est haskell. Afficher tous les articles

dimanche, avril 04, 2010

Java vs Haskell


At that time I did not know it, but I was doing some kind of functional programming. I discovered Haskell a few weeks ago, and I duplicated what I did in Java.

As you can guess the Haskell code is way shorter, and goes even a little further.

1 Have a list of people belonging to various countries:
European people: [Eric from France, Martine from France, John from Great-Britain, Martha from Great-Britain, Carine from France, Gerd from Deutschland, Giuseppe from Italia, Martha from Deutschland]

2 Get the different countries:

European countries: ["Deutschland","France","Great-Britain","Italia"]

3 List the people that belong to each country
:
People from: [France]: [Carine from France, Eric from France, Martine from France]
People from: [Deutschland]: [Gerd from Deutschland, Martha from Deutschland]
People from: [Great-Britain]: [John from Great-Britain, Martha from Great-Britain]
People from: [Italia]: [Giuseppe from Italia]

Here is the code:
import Data.List
import Data.Function

le = [
("Eric", "France"),("Martine", "France"),
("John", "Great-Britain"),("Martha", "Great-Britain"),("Carine", "France"),
("Gerd", "Deutschland"),("Giuseppe", "Italia"),("Martha", "Deutschland")
]

dla xs = "European people: " ++ show [ fst x ++ " from " ++ snd x | x <- xs]
lc xs = [ head y | y <- group(sort([ snd x | x <- xs]))]
dlc = "European countries: " ++ show(lc le)

lpc5 xps = groupBy (\x y -> snd x == snd y) (sortBy (compare `on` snd)([ xp | xp <-xps ]))
lpc9 xps = unlines [ "People from " ++ show (snd (head xp)) ++ ":" ++ (show [fst x | x<-xp ]) | xp <-xps ]
fait9 = do { m <- [lpc5 le]; lpc9 m }
dlad = [ dla le, dlc, fait9 ]

main = putStrLn (unlines(dlad))

mercredi, mars 24, 2010

Getting Haskell XML Toolbox to run on windows

First of all, as of today (march 2010), you have to use the version 8.3.2.
you'll need to install tagsoup-0.6: link
cabal install tagsoup-0.6

then you'll need to install curl:
basically it does not work.

you must install cygwin with curl libraries installed.

running cabal install curl under cygwin will give you some errors even when following these advice: Installing curl from hackage on Cygwin
but do the asked copy anyway because, it maybe useful for the final solution.

you can also try to run these commands instead of running cabal link
download curl from http://hackage.haskell.org/packages/archive/pkg-list.html
cd xxx/curl-1.3.5
runhaskell Setup.hs configure --extra-include-dirs=c:/SandBox/cygwin/usr/include --extra-lib-dirs=c:/SandBox/cygwin/lib
you'll get an error but continue with the next commands.
runhaskell Setup.hs build
runhaskell Setup.hs install
it will tell can't find curl lib.
I can also remember that I had to hardcode some values in curl.c because it could not find the ones defined in curl.h

What I finally did, and I think that is the only thing you need to do:
get the win32 generic version of libcurl from http://curl.haxx.se/download.html : http://www.gknw.net/mirror/curl/win32/curl-7.20.0-devel-mingw32.zip
extract the zip
copy all the lib/*.lib in the lib directories from cygwin and haskell_ghc
copy bin/*.* in the cabal_haskell/bin directory where tagsoup.exe is already present.

install hxt
then either run cabal install hxt-8.3.2 or download the hxt package and run
cd xxx/hxt-8.3.2
runhaskell Setup.lhs configure
runhaskell Setup.lhs build
runhaskell Setup.lhs install



vendredi, mars 19, 2010

Getting Haskell Running on Eclipse - 2010 updated

I wanted to get Haskell running on Eclipse so I tried to do as the video below is saying:

The problem I got when following the video is that it did not work exactly as shown, so, here is my modest contribution to give additional hints on how to have Haskell running on eclipse.

install haskell eclipse plugin
get http://hackage.haskell.org/platform/
install
get http://cvs.haskell.org/Hugs/pages/downloading.htm
install
get http://www.haskell.org/cabal/download.html
execute "cabal" in a dos windows and follow instructions
http://imonad.com/blog/2009/10/installing-haskell-plugin-for-eclipse/
in C:\Program Files\Haskell\bin
execute "cabal update" in a dos windows
execute "cabal install scion" in a dos windows
in C:\Program Files\Haskell\bin you should find scion-server.exe that you'll need it in haskell preferences.