haskell

How to print integer literals in binary or hex in haskell?

How to print integer literals in binary or hex in haskell? printBinary 5 => "0101" printHex 5 => "05" Which libraries/functions allow this? I came across the Numeric module and its showIntAtBase function but have been unable to use it correctly. > :t showIntAtBase showIntAtBase :: (Integral a) => a -> (Int -> Char) -> a -> String...

Haskell type cast problem

Example code: fac :: Int → Int fac 0 = 1 fac n = n * fac (n-1) main = do putStrLn show fac 10 Error: Couldnt match expected type 'String' against inferred type 'a -> String' In the first argument of 'putStrLn', namely 'show' In the expression: putStrLn show fac 10 ...

simple yes/no haskell list question

So I'm reading http://learnyouahaskell.com/starting-out as it explains lists, and using ghci on Vista 64. It says that [2,4..20] steps by 2 from 4 to 20. This works. It says [20,19..1] goes from 20 to 1, but doesn't explain. I take it that the first number is NOT the step, the step is the difference between the 1st and 2nd number. This i...

What should a software engineer (web) start by learning - Erlang, Haskell, Python, C++, F#

What would you suggest what will be the next choice of language that could benefit an engineer in his career utmost? I am a Software Engineer and almost everything I engineered is for WWW. I have decided to learn a language and keep it learning parallel. I'm fluent in C# and JavaScript. But, apart from it I want to learn a language whic...

No instance for (Floating Int)

I am learning Haskell. I have created function which returns multiplication table up to 'n' in base 'b'. Numbers are padded to 'w' digits. As the last step, I want to compute 'w' automatically. Why does this not compile? -- Number of digits needed for the multiplication table n*n in base 'base' nOfDg :: Int -> Int-> Int nOfDg n base = ...

What can be improved on my first haskell program?

Here is my first Haskell program. What parts would you write in a better way? -- Multiplication table -- Returns n*n multiplication table in base b import Text.Printf import Data.List import Data.Char -- Returns n*n multiplication table in base b mulTable :: Int -> Int -> String mulTable n b = foldl (++) (verticalHeader n b w) (map (...

Pattern matching against a tuple in the IO Monad in Haskell

I've been studying Haskell in my spare time and have recently crossed into the area of monadic functions. I've distilled the code from an excercise I've been working on into this very contrived example to isolate the exact problem I'm having: import System.Random rndPermu :: [a] -> IO (a, [a]) rndPermu xs = (front, back) where (fro...

How to write CGI script using Haskell?

if i want to make a web application, for example, it could be a blog, forum, or some dynamic web pages, what do i need? i know that i need an http server(apache, lighttpd). i know that i should know some programming language to develop this web app. but how it all combine? can i develop in any (exotic) programming language? for example,...

Efficiency of equality in Haskell

Hi, I've got a function that takes data and either returns the same data or a slightly modified version. I want to have my program do one thing if it changed or another thing if it did not change. Previously I was returning a pair (Bool,Object) and using fst to check if it changed. Lately it occurred to me that I could simplify the c...

trying to install hs-ffmpeg haskell package fails to find libdc1394

doing "cabal install hs-ffmpeg" fails like this: checking for faacEncGetVersion in -lfaac... no checking for zlibVersion in -lz... yes checking for libdc1394... configure: error: Package requirements (libdc1394) were not met: No package 'libdc1394' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed soft...

using cabal readline package on i386 macbook (snow leopard)

Hi, I'm trying to build and install readline on a i386 MacBook with Snow Leopard. I have made the following steps: download and extract readline-6.0.tar.gz ./configure make everything sudo make install I checked the examples and they appear to work (for instance rltest has support for history). This is the output of file libreadline...

haskell fastCGI on lighttpd, need help with configuration

I'm trying to setup a lighttpd server that will run fastCGI programs written in haskell. So far i got this haskell program: import Network.CGI import Text.XHtml page :: Html page = body << h1 << "Hello World!" cgiMain :: CGI CGIResult cgiMain = output $ renderHtml page main :: IO () main = runCGI $ handleErrors cgiMain and this li...

Good Haskell coding standards

Could someone provide a link to a good coding standard for Haskell? I've found this and this, but they are far from comprehensive. Not to mention that the HaskellWiki one includes such "gems" as "use classes with care" and "defining symbolic infix identifiers should be left to library writers only." ...

Why doesn't this type declaration work?

I'm trying to create a 'Person' type where each person has a sex and a name. data Sex = Sex Char deriving Show male = Sex 'M' female = Sex 'F' data Name = Name [Char] deriving Show data Person = Person { Sex :: Sex, Name :: Name } deriving (Show) When I try to load this in ghci I just get the unhelpful error ...

trying to install cabal package sdl-mpeg can't find include file smpeg.h

running "cabal install sdl-mpeg" $ ls -l /usr/include/smpeg/smpeg.h -rw-r--r-- 1 root root 7503 2008-11-05 18:07 /usr/include/smpeg/smpeg.h $ cabal install sdl-mpeg Resolving dependencies... Configuring SDL-mpeg-0.0.1... cabal: Missing dependency on a foreign library: * Missing header file: smpeg.h This problem can usually be solved b...

Partial Application of Infix Functions in F#

In haskell it is posible to partially apply an infix function using sections, for instance given the infix function < (less than) one can partially apply any of the function's arguments: (5 <) , (< 5) In other words, in haskell we have the following shorthand notation: op :: a -> b -> c (`op` y) === \x -> x `op` y (x `op`) === \y -> x...

Distributing a Haskell program as C source

Say I have a Haskell program or library that I'd like to make accessible to non-Haskellers, potentially C programmers. Can I compile it to C using GHC and then distribute this as a C source? If this is possible, can someone provide a minimal example? (e.g., a Makefile) Is it possible to use GHC to automatically determine what compile...

Haskell -- problem with pretty-printing a list

I'm new to haskell, and i read through and digested Learn You A Haskell For Great Good, trying out a couple of things along the way. For my first project i wanted to try the classic: FizzBuzz. So i came up with the following code: import System.IO fizzBuzz :: (Integral a) => a -> String fizzBuzz num | fizz && buzz = "FizzBuzz" ...

Haskell -- "The last statement in a 'do' construct must be an expression"

Like it says in the tile: what does The last statement in a 'do' construct must be an expression mean? I ended my do block with a putStrLn like it shows in several examples I've seen, and i get an error. Code: main = do args <- getArgs file <-readFile "TWL06.txt" putStrLn results And i just realized why it's like that.......

read token after token from a file in haskell

Hi everybody! I want to read from a file in Visual Haskell Studio, token after token, by loading each time the next token in a variable. For example: getNextToken. Thanks!! :) ...