Skip to content

Commit 4d2781b

Browse files
committed
Add haskell implementation
1 parent d89a841 commit 4d2781b

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
FROM ubuntu
22
MAINTAINER Judit Acs
33
RUN apt-get update
4-
RUN yes | apt-get install -y wget curl gcc g++ nano python perl php5 git default-jdk time software-properties-common mono-mcs
4+
RUN yes | apt-get install -y wget curl gcc g++ nano python perl php5 git default-jdk time software-properties-common mono-mcs ghc cabal-install
55
RUN yes | apt-add-repository ppa:staticfloat/juliareleases
66
RUN yes | apt-get update
77
RUN yes | apt-get install julia
88
RUN yes | apt-get install golang-go
99
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
1010
RUN sudo apt-get install --yes nodejs
11+
RUN cabal update
1112
RUN git clone https://github.com/juditacs/wordcount.git
1213
RUN locale-gen en_US.UTF-8
1314
ENV LANG en_US.UTF-8

haskell/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

haskell/WordCount.cabal

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: WordCount
2+
version: 0.1.0.0
3+
-- synopsis:
4+
-- description:
5+
-- license:
6+
--license-file: LICENSE
7+
author: Larion Garaczi
8+
maintainer: l4rion@gmail.com
9+
-- copyright:
10+
category: Language
11+
build-type: Simple
12+
cabal-version: >=1.8
13+
14+
executable WordCount
15+
main-is: WordCount.hs
16+
-- other-modules:
17+
build-depends: base ==4.6.*, containers ==0.5.*, unordered-containers ==0.2.*, text ==1.2.*
18+
ghc-options:
19+
-O2
20+
-with-rtsopts=-H512M

haskell/WordCount.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import qualified Data.Text as T;
2+
import qualified Data.Text.IO as TextIO;
3+
import qualified Data.List as L;
4+
import qualified Data.HashMap.Strict as H;
5+
import Data.Monoid;
6+
7+
main = TextIO.interact (T.concat . map formatOutput . countWords) where
8+
formatOutput (word, count) = T.concat [word, T.singleton '\t', T.pack . show $ count, T.singleton '\n']
9+
10+
countWords :: T.Text -> [(T.Text, Int)]
11+
countWords = L.sortBy (\(a, b) (c, d) -> compare d b <> compare a c) .
12+
H.toList .
13+
H.fromListWith (+) .
14+
map (\word -> (word, 1)) .
15+
filter (/=T.empty) .
16+
T.split (`elem` "\n\r\t\f ")

run_commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ python/wordcount_py3.py
1313
php php/wordcount.php
1414
go/bin/wordcount
1515
mono csharp/WordCountList.exe
16+
haskell/WordCount

scripts/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ go install wordcount
1919

2020
cd ../csharp
2121
mcs WordCountList.cs
22+
23+
cd ../haskell
24+
cabal install --verbose=0
25+
cp dist/build/WordCount/WordCount .

0 commit comments

Comments
 (0)