haskell

How is (==) defined in Haskell?

I'm writing a small functional programming language in Haskell, but I can't find a definition of how (==) is implemented, as this seems to be quite tricky? ...

Haskell Conditionals

Hi, I'm having some difficulty integrating && within Guards eg: something :: Char -> Int something k | ord k >= 77 && ord k <= 98 = 8 | otherwise = 88 How the heck can i achieve the above without setting off an error? Cheers. ...

Optimisations for a series of functions in Haskell

Hi I am trying to do problem 254 in project euler and arrived at this set of functions and refactor in Haskell: f n = sum $ map fac (decToList n) sf n = sum $ decToList (f n) g i = head [ n | n <- [1..], sf n == i] sg i = sum $ decToList (g i) answer = sum [ sg i | i <- [1 .. 150] ] Where: f (n) finds the sum of the factorials ...

How do I get Cabal to bypass my Windows proxy settings?

When retrieving packages with Cabal, I frequently get errors with this message: user error (Codec.Compression.Zlib: premature end of compressed stream) It looks like Cabal is using my Windows Networking proxy settings (for Privoxy). From digging around Google, Cabal or its libraries appear to have (had) a problem in this area. ...

Haskell: Force floats to have two decimals

Using the following code snippet: (fromIntegral 100)/10.00 Using the Haskell '98 standard prelude, how do I represent the result with two decimals? Thanks. ...

CMS in functional programming language

Are there any CMS'es, written in functonal programming languages (lisp, haskell, f#/nemerle, scala, erlang, clojure, smalltalk) already? ...

Does functional programming mandate new naming conventions?

I recently started studying functional programming using Haskell and came upon this article on the official Haskell wiki: How to read Haskell. The article claims that short variable names such as x, xs, and f are fitting for Haskell code, because of conciseness and abstraction. In essence, it claims that functional programming is such a...

how to install haskell openid package in windows

haskell 'openid' package depends on HsOpenSSL and nano-hmac packages which requires openssl. I've compiled openssl for MinGW in C:\OpenSSL\ directory and installed openid package with following command: cabal install openid --extra-include-dirs=C:\OpenSSL\outinc --extra-lib-dirs=C:\OpenSSL\out When I'm trying to compile haskell progra...

Evaluating parsed expression in Haskell

This is my first question on SO :) My Haskell knowledge is pretty limited, so i need a bit of help to get me started. I have this BNF grammar: num ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 int ::= num | num int var ::= A | B | C | ... | Z expr ::= var | int | - expr | +(expr , expr) | *(expr , expr) | let var be expr in...

choose Linux distribution for Haskell development

Which Linux version is the most comfortable for haskell development? I want to install ghc and compile Leksah in it. I'm using CentOS now but it's repository is not rich and fresh enough. ...

How to make Haskell use another list depending on the previous answer in Haskell

Hi I am doing project euler question 63 where I must find the amount of numbers that exist where: x^(n) == y Where n is the length of y. It soon emerges that the results for this condition alternate between odd and even and so I came up with this in Haskell: prob63 = [ n | n <- nums n , i <-[1..10], i^(length $ show n) == n] nums n...

How can I resolve this ambiguous type variable error?

The following code compiles just fine, but I cannot use my function: CODE: g :: (Fractional b, Integral b) => Int -> b -> b g 1 x = x / (g 2 x + 1) g 100 x = 2401*x/100 g n x = ((map (\z -> (ceiling z)^2) (1:[0.5,1..]))!!(n-1))*x / ((g (n+1) x) + fromIntegral n) ERROR: Ambiguous type variable `t' in the constraints: `Integral t' ari...

Haskell. Why Array faster then lists ?

Hello. I am study the Haskell. I am have the next question : The List type is basic type in haskell. Array in haskell based on lists . This is list of indices [Ix a] and function presents by table - list of pairs [(Ix a,Value)]. Why Array faster then lists, if inside it use lists ? Thank you. ...

Multiple Statements In Haskell

How do you have multiple statements in haskell? Here's what I'm trying to do: given a list such as [a,b,c,d], return every other element, so you get [a,c]. I can see the solution, and here's what I have so far: fact (xs) | length( xs ) `mod` 2 == 1 = head( xs ) | otherwise = fact(tail( xs )) This works fine the first time around,...

Haskell. Strict application $!

I execute the next code: (take 10) $! [1,2..] What is it ? I thought, ghc will yield a termination, beacause i say "evaluate [1,2..] force". But I got the result "[1,2,3,4,5,6,7,8,9,10]". ...

asm / C / Python / Perl / Lisp / Scheme Programmer looking for something new to learn.

I need to have an at-home project now that I'm working on Python/Django at work. I'd like to learn something new, so I was thinking of checking out Java. What's the most well respected web framework for deploying Java web apps? The only reason I'm not checking out ruby on rails is because of how similar the ORM and other parts are to Dj...

Haddock for Cabal-installed modules?

I'm using GHC and have installed several packages via Cabal. One of the packages' web site says "go see the haddock documentation". The haddock command seems to only work on source files, and cabal haddock only seems to work in the top-level directory of a project with a .cabal build file. Is there a way to say "show me the haddock" for ...

Haskell lexer problems

I'm writing a lexer in haskell. Here's the code: lexer :: String -> [Token] lexer s | s =~ whitespace :: Bool = let token = s =~ whitespace :: String in lex (drop (length token) s) | s =~ number :: Bool = let token = s =~ number :: String in Val (read token) : lex (drop (length token) s) | s =~ operator...

Issue with Haskell's "do"

Hello. I wrote a Haskell function that calculates the factorial of every number in a given list and prints it to the screen. factPrint list = if null list then putStrLn "" else do putStrLn ((show.fact.head) list) factPrint (tail list) The function works, but I find the third line a bit confusing. Why hasn't the compiler(GHC) repo...

Operate on values within structurally similar types in Haskell

Excuse me for my extremely limited Haskell-fu. I have a series of data types, defined in different modules, that are structured the same way: -- in module Foo data Foo = Foo [Param] -- in module Bar data Bar = Bar [Param] -- * many more elsewhere I'd like to have a set of functions that operate on the list of params, eg to add and ...